Skip to main content

Full text of "Plus 4 Users Manual"

See other formats


5 ■ 


1 

User's Manual 

■ 


3-« 


li' 1 i 1 





mmmmmm 



Ja«7a«T«Ma 



SSS£ ^ B"! '^ '<*' ^^ .^ '^ ^^. ^^. >* 










^^m 


■MMBM^^HaMHMHMMMHMM^di_ 1 . 


mmm 


^^^ 



USER'S 

MANUAL 

STATEMENT 



"This equipment generates and uses radio frequency energy, if it is 
not properly installed and used in strict accordance with the manu- \__^ 

facturer's instructions, ttiis equipment may interfe''e with radio and 
television reception. This machine has been tested and found to com- 
ply with the limits for a Class B computing device in accordance with ' — ' 
the specifications in Subpart J of Part 15 of the FCC Rules, which are 

designed to provide reasonable protection against such interference . 

in a residential installation. If you suspect interference, you can test 
this equipment by turning it off and on. if you determine that there 
is interference with radio or television reception, try one or more of 
the following measures to correct it: 

• reorient the receiving antenna 

• move the computer away from the receiver 

• change the relative positions of the computer equipment and — " 
the receiver 

• plug the computer into a different outlet so that the computer . 

and the receiver are on different branch circuits 

If necessary, consult your Commodore dealer or an experienced radio — 
television technician for additional suggestions. You may also wish to 
consult the following booklet, which was prepared by the Federal __ 

Communications Commission: 

"How to Identify and Resolve Radio-TV Interference Problems " — - 

This bool<let is available from the U.S. Government Printing Office, 
Washington, D.C. 20402, Stock No. 004-000-00345-4.' 



You should use only the cables, accessories, and peripherals re- 
commended by Commodore for your Plus/4. All cables, including the 
cables lor the television liookup, serial port, video port, Datassette^" 
and joysticks, are specially shielded, in accordance with the regula- 
tions of the Federal Communications Commission. Failure to use 
the appropriate accessories and cables will invalidate the FCC grant 
of certification, and may cause harmful radio interference. 

Copyngtil ig 1964 by Coinmociore Eleclronics Lirntled 

All righls reserved 

This manual contains copyngnied and proprietary information No pari ol ttiis publicalian 

may be reproduced, stored in a retrieval system, or transmitted in any form or by any 

means, electronic, mechanical, photocopying, recording or otherwise, without the prior 

wrilten permission of Commodore Electronics Limited 

Commodore BASIC V 3 5 

Copyright {S; 1984 by Commodore Electronics Limiled,all rights reserved 
Copyrighl © t977 by Microsoft, all rights reserved. 






u 



n 



n 



COMMODORE PLUS/4 
USER MANUAL 



TABLE OF INTRODUCTION 1 J 

CONTENTS CHAPTER 1 unpacking and Setting Up 1 ^ 

CHAPTER 2 Using the Keyboard and Screen 22 

CHAPTER 3 Using Software 33 ■ — 

CHAPTER 4 Getting Started 42 

CHAPTER 5 Beginning BASIC 58 

CHAPTER 6 Numbers and Calculations 68 ' 

CHAPTER 7 Using Graptiics and Color 83 , 

CHAPTER 8 Making Sound and Music 104 

COMMODORE PLUS/4 ENCYCLOPEDIA 113 

1 —J 

1 BASIC 3.5 Encyclopedia 115 

Commands . . , 1 lis— i 

Statements 1 30 

Functions 1 5&— ^ 

Variables and Operators 16^ 

2 BASIC 3.5 Abbreviations 169 

3 Conversion Programs 1 71— i 

4 Error Messages \ic , 

5 TEDMON 184 

6 Screen Display Codes 19j— ' 

7 ASCII and CHRS Codes 19E_j 

8 Screen and Color Memory Maps .199 

9 Memory Register Map 201 — 

10 Deriving Mattiematical Functions 20; ^ 

11 Musical Note Table 204 

1 2 Programs To Try 206 

^ -1 



n 



n 



13 RS-232 Guidelines 209 

14 Book List ■ 215 

INDEX 216 



m 

m 
m 
m 
m 



INTRODUCTION 




n 



You've made a wise purchase ... the Plus/4 is the first home computer 
ever designed especially for productivity applications. Of course, it's 
still able to do all the other things a home computer can be used for. 
This manual is designed to help you learn those "other things" your 
Plus/4 can do. You'll learn how to: 

• Set up your Plus/4 

• Use the different functions of all the keys on the keyboard 

• Access different types of Commodore Software 

• Use the mathematical, graphics, sound and programming 
capabilities of your Pius/4 

The other manual included with your computerfT/ie Plus'4 Built-in 
Integrated Software Manual) telis you how to use the wordprocessing, 
electronic spreadsheet, database and graphics packages. If your 
main interest is in these productivity applications, and you can't wait to 
get started using them, we still recommend that you read through at 
least chapter one of this manual ("Unpacking and Setting Up") before 
reviewing the Built-in Software Manual. 



n 



u 



WHAT'S 
SPECIAL 

ABOUT 
THE 

PLUS/4 



64K RAM (60K available for BASIC programming) 

Full Typewriter Style Keyboard 

Optional Built-in Software 

Screen Window Capability 

HELP Key 

8 Pre-programmed, Reprogrammable Function Keys 

Four Separate Cursor Keys 

Uses Most COMMODORE 64 and VIC-20 Peripherals 

121 Colors (16 primary colors, 8 luminance levels) 

Over 75 BASIC Commands 

High Resoiution Graphics Plotting 

Split-Screen Text With High-Res Graphics 

Graphic Character Set On Keyboard 

Keyboard Color Controls 

320 X 200 Pixel Screen Resolution 

Reverse and Flashing Characters 

2 Tone Sound Generators 

Built-in Machine Language Monitor (17 commands) 



CREATING 

A COMPLETE 

COMPUTER 

SYSTEM 



y 
m 




Computer: Commodore PLUS/4 



-^ 




n 




Display: Commodore 1702 or 1802/1803 Color Monitor 



n 



J 




Storage: Commodore 1531 Datassetle (tape recorder) or Commodore 
Disk Drive 




Printer: Commodore Printer 



4—' 




n 



n 



Modem: Commodore 
MODEM/ 300 





Controller: Commodore PLUS/4 Joysticks 



-1 



WHERE ^y "^^^ you've done enough reading and you want to get started. 
jn Here's wtiat we recommend you do now: 

FROM • Send in your warranty card 

HERE? • Subscribe to the Commodore magazines to get the latest informa- 
tion on your computer 

Read this manual and try the exercises. Read the built-in software 
manual and get used to the four integrated packages. Keep checking 
in with the Commodore dealers in your area for new developments in 
software, books and peripherals. Learn, program, file, write, calculate, 
graph, play . . . enjoy your new Commodore PlusMl 



m 
m 
m 
m 
m 



CHAPIER 1 



UNPACKING 
AND 
SEUING 
UP 





Unpacking your Commodore Plus/4 




Getting to know the switches and sockets 




Setting up your Commodore Plus/4 




Troubleshooting chart 




Peripherals 





UNPACKING ^'^^^^^^^^^at^Kiu^^^ 

COMMODORE ^°^ '^^^^ -" "^e Uems on'hSs't Von?.L^ .*:^ '^'^^^k to ^ake sure tha 

PLU&^4 



lis list. You should have- 



that 




1- Vour Commodore Plus/4 




2. The power supply 
thetompulef '"'° ' ^^" °^"^'' '^^ °'^Br plugs .,o the nght s.de of 




TheTVswitchbox 

This connects to tine antenna jack on the back of your TV. You don't 

need the switchbox if you plan to connect your Plus/4 to a monitor. 




4. The RF cable 

This connects the TV switchbox to the RF output jack on the left 
side of the Plus 4. You don't need this cable to connect your Plus'4 
to a monitor. 



. 1 



5, The user manual 

6 Other assorted literature 
Warranty card 
Commodore (Magazines subscription card 

7, The Plus/4 Built-in Integrated Software Manual 

If you don't find all these items in the box, check with your dealer 
immediately for replacements. 

Before you connect anything, you should look over these drawings of 
your computer. These drawings identify all the outlets so you can set 
up your computer system quickly and easily. 



J 



GETTING 

TO 

KNOW 

THE 

SWITCHES 

AND 

SOCKETS 

The Right 

Side 

of Your 

PLUS/4 

1 




2 1 



■J 



The On/Off Switch 

Your Plus/4 should be turned OFF when you install or remove car- 
tridges or any peripheral device such as a printer or disk drive There 
is a red power light located below the keyboard on the left, so you 
can be sure whether power is off. 

2 The Reset Button 

There are two ways to use the RESET button: 

1 . You can use the RESET button to reset your computer as if you'd 
just turned it on. Just press the reset button once. Remember: when 
you press the reset button, you lose any BASIC program currently 
in memory.* 

2. If you want to reset your Plus/4 and keep your BASIC program, 
hold down the RUN/STOP key and then press the RESET button. When 
you do this, your Plus/4 goes to the built-in machine language monitor. 
Type an X and press the RETURN key to get back to BASIC. Your pro- 
gram remains intact in the Plus'4 memory. Just type LIST to display the 
program on your screen. 

*When you press RESET, the Plus/4 automatically issues the NEW 
command, which clears the screen. This can be reversed. See the 
Plus'4 Programmer's Reference Guide for information on UNNEWing 
your program if you've pressed the reset button by accident. 



10 _^ 



The 

Left 

Side 

Of 

Your 

PLUS/4 



n 




The socket and the switch on the left side of the Plus/4 are both used 
for TV connections. Neither Is used If you're connecting your Plus/4 to 
a monitor. 

3 The RF Jack 

This Is where you plug In one end of the RF cable (the thin black 
cable), You can plug either end into this lack and the other end into the 
TVswItchbox. 

4 The High/Low Switch 

This switch controls which channel Is used for Plus/4 video output. Set 
the H/L switch to L for output on channel 3. Set the H/L switch to H for 
video on channel 4. 



The 
Back 

of 

Your 

Computer 



You can use either channel 3 or 4 on your TV to display the video pic- 
ture from your computer. If you have a channel 3 TV station in your 
area, select channel 4, and vice versa. Experiment to see which setting 
gives you the best picture. 



M^f/-7.f/r-f--ff.^'-».>- 



i ir w r^ ^ "^ -* '^_^ V. >-^ *;.>,^ ^^, " 



w 



5 6 7 



10 11 



11 



The sockets on the back of your computer connect a vanety of 
accessories to your Plus'4. Each connector is different. Be sure 
you plug each accessory into the correct socket. 

5 The Power Socket 

The end of the power supply cable fits here. Plug the other end 
into a standard wall socket for three-prong plugs. 

g The Serial Bus 

You can plug a disk drive or a printer into this socket. If you want to 
plug in both, first plug the disk drive into this opening, then plug the 
printer cable into the back of the disk drive, 

7 The Cassette Port 

The Commodore 1531 Datassette tape recorder plugs in here. 



8 The RS-232 Port 

Accessories such as a modem or an RS-232 adapter plug in here. 
An RS-232 adapter makes it possible to hook up accessories not ac- 
commodated by standard Commodore equipment ports. 

g The Memory Expansion Port 

Plus'4 software cartridges and the Plus/4 SFS-481 disk drive plug in 
here. Before you install or remove cartridges, make sure your Plus.'4 
is OFF 

■JO Joy 1 and Joy 2 : The Game Ports 

You can plug joysticks into these sockets. The Plus.'4 uses specially 
designed joysticks available from your Commodore dealer. 



11 The Video Socket 

This is where you plug in the cable that connects a monitor to your 
Plus/4, Although this socket is an 8-pin connector, you can use a 5-pin 
cable in this socket as well. Commodore color monitors come with an 
8-pin cable for use with the Plus/4, 



12 



SETTING 

UP 

YOUR 

PLUS/4 



• To set up your Plus/4, you'll need at least two wall plugs one for your 
P!us/4 and one for your TV or monitor. 

• If you're installing a disk drive and a pnnier, you'll need additional 
wall plugs 

• Your PluS'4 sfiould be placed a comfortabte distance from your TV 

• fvlake sure that your computer is OFF before you start tfie setup 
Check that the POWER LIGHT on tfie front left is not lit. 

If you are connecting the Plus'4 to a television set, you'll need a 
small screwdriver to attach the TV switchibox. The way you connect 
the switchbox depends on what type of antenna connection your TV 
set fias. 

IfVIPORTANT: If your antenna is connected to your TV by a single 
round-ended cable {tfie 75-ohm co-ax type), you will need eitfier 
the 300 ohm to 75 ohm adapter, which came with your TV, or you 
must get a replacement 75 ohm to 75 ohm switchbox. The adapter 
is a small plastic part with a co-ax connector on one side and two 
screws on the other If you do not have one, you can buy one at 
most electronics stores. Once you attach the adapter to the co-ax 
connector on your set, you can follow the rest of thiese instruc- 
tions A 75-ohm switchbox allows you to hook the antenha lead 
into the switchbox, which is connected to (he TV. so that you only 
have to move the switch on the switchbox to watch TV. 

You need only connect the switchbox once. When you want to use your 
computer, just move the switch to the COMPUTER position When you 
want to watch TV, move the switch to TV. The switchbox will not 
interfere with your TV reception. 



13 



J 



STEP 1 Disconnect the antenna Irorn your TV: use a screwdriver to 

loosen the screws on ttie TV Remove the two antenna leads. 
STEP 2 Connect ttie TV swilchbox to Itie TV wtiere llie antenna leads 

were attach Itie leads on Ihe box to the antenna inpul on 

your TV 
STEP 3 Connect the antenna to the switchbox attach ihe leads from 

the antenna to Ihe screws on the side ol Ihe switchbox 



-J 




RF Cable 



3 



Power Supply 



If you have the round coan type antenna connection on your TV 
STEP 1 Disconnect the antenna from your TV unscrew Ihe antenna 

wire You can disconnect it by hand 
STEP 2 Conned Ihe swilchbox to your TV hand fasten it onto Ihe 

antenna input post on Ihe back of your TV 
STEP 3 (For Ihe 75-ohm switchbox) Connect the anienna to Ihe 

switchbox hand-turning the anienna cable into the 

switchbox 



Li 



. 4 



If an Adapter 
Is Necessary 



Remove to Connect 

Antenna 

Lead 10 TV 




Once the switchbox is m place, gel the RF cable (the Itim cable with 
y^ connectors on both ends} Itiat came v/ilh your PluS'4 Plug one end into 

./' 'he socket on ttie side of ttieswiictibox. Connect theottier end into the 

socket marked RF on ttie left side of your computer 

NOTE II youVe using the 300- to 75-otim adaptor and you want lo 
watcti TV, you musl disconnect tfie switctibox and plug the an- 
tenna lead back in This is easily done by hand, and may be 
Oone as often as you like, wilh no damage to your TV. computer. 

I or antenna 

I _ 

SBlBCtina as we explained earlier, your TV should be set on either channel 3 
' A ChdnnBl '^'' ^ when you are using your computer. Don't choose a channel that 

On Your TV broadcasts in your area. If you use channel 3, set the H.'L switch on the 
side of the computer to L. If you use channel 4. set this switch to H. 

ConneCtinQ Your " you're connecting your computer to a monitor instead of a TV. follow 
' rnmmnrlnrp PI I K/d "^^ instructions in the manual Iha! is included with the monitor. Hook- 
tDmmDQOre rLUo/4 |^g ^jp g monitor, lil<e the Commodore 1702 Color Monitor, is simple. It 
. to a Monitor requires only one cable that connects directly from your monitor to 

the VIDEO socket in the back of your computer. 



15 



Final ^- Attach the power supply cable from the power box to your PIusM. 
Ctpnc Plug ihe round end of the cable Into the POWER socket on the 

" back of the computer: plug the power supply into the wall socket, 

2. If you are using a TV. make sure that the setting on the H/L mod- 
ulator and the channel on your TV are in agreement. (If your com- 
puter is set at L, the TV must be on channel 3: the TV should be 
tuned to channel 4 with your computer at H.) Make sure that the 
switchbox is set to the COMPUTER setting. 

If you are using a Commodore color monitor, use the rear jacks, 
and check that the backfront switch is set to back. 

3- Turn on your computer. (The switch is on the right side as you 
face the Plu5/4.) 



If all is well, this message appears on your screen: 
COMMODORE BASIC 3.5 60671 BYTES FREE 
READY. 



The flashing cursor under the READY message tells you that the 
Plus/4 is wailing for you to start typing. The background color is 
white, while the letters are printed in black, with a light purple 
border around the screen. 

4. Check the troubleshooting chart if you have problems. You may 
need to adjust your TV set to get a sharper picture. 



16 



-TROUBLESHOOTING 
CHART 



n 



Symptom 



Cause 



Indicator light 
not 'ON' 



No picture 



Computer not 
turned ON 



Power cable not 
plugged in 

Power supply not 
plugged in 

Bad fuse in 
computer 



TV on wrong 
channel 

Incorrect hookup 



Video cable not 
plugged in 

Computer set for 
wrong channel 

Switchbox not 
set to computer 

TV not on 



Random pattern Cartridge not 
on TV with properly inserted 

cartridge in place 



Picture without 
color 



Poorly tuned TV 



TV not connected 



Remedy 



Make sure power 
switch is in ON 
position 

Check power socket 
for loose or discon- 
nected power cable 

Check connection 
with wall outlet 

Take system to au- 
thorized dealer for 
replacement of fuse 



Check other channel 
for picture (3 or 4) 

Computer hooks up to 
VHF antenna terminals 

Check TV output 
cable connection 

Set computer for same 
channel as TV 

Check that switchbox 
is in 'computer' position 

Turn TV on 



Reinsert cartridge 
after turning OFF 
power 



RetuneTV 

Check connections 
properly 



n 



17 



Picture OK, 
but no sound 



TV volume too low 



Poorly tuned TV 

Auxiliary output not 
properly connected 



Adjust volume of TV 



Retune TV 

Ctieck connection as 
shown on diagram on 
page 14-15 



IMPORTANT: Some TV sets cannot display the entire Plus/4 
screen. Instead, their picture cuts off the far left and far right 
column of the Plus/4 screen display. We recommend using a 
different TV set or a monitor such as the Commodore 1702 or 
1802/1803 color monitor. 

If this is not possible, you can deal with the problem by pressing 
the ESCape key, followed by the 'R' key. This reduces the com- 
puter screen display size so the entire picture can fit onscreen. 
You must repeat this each time you power up or reset your Plus/4. 



._J 



a 



18- 



— PERIPHERALS Peripherals are the accessories that you can add to your Plus/4 sys- 

tem. These accessories are available at your Commodore dealer, and 
allow you to use the Plus/4 to the fullest. Peripherals give your Plus/4 
" system the capability to store and save data, prim hard copy (in black 

and white or color), use disk and cassette-based software, and access 

— ^ the information and services available through telecommunications. 




To save or recall programs, you'll need a device that stores data, Data 
can be stored on and retrieved from both diskettes and cassette tapes. 
To use diskettes, you'll need a DISK DRIVE, Disk drives are typically 
fast and efficient to use. Disk drives that are compatible with your 
Plus/4 are the Commodore models 1541 and 1551 . For cassette-based 
storage and retrieval, the Commodore 1531 DATASSETTE tape 
recorder fills the bill. 




n 



19 




When using a wordprocessing program or a graphics package on the 
Plus.'4, a printer will reproduce what is on the screen on paper. There 
are several models o1 Com;modore printers available that work with the 
PIus/4. These include the MCS-801. MPS-802, MPS-803 (with tractor- 
feed) and DPS-1101 (letter quality). Different printers specialize in dif- 
ferent types of print-outs. Ask your dealer which best suits your needs. 




Your television may not give you as clear a picture as youd like for your 
computer. Commodore color monitors are specially designed to give 
you the sharpest, brightest picture for your Plus. 4 screen output. There 
are several Commodore monitor models available, including the 1702. 
and 1802/1803, 



20 





There are networks thai you can reach over the phone whose purpose 
is to provide information, programs, news, stock market reports, enter- 
tainment, and almost anything else you could think ol to computerists 
by using the phone lines. To gam access to the tremendous range of 
services, soflware. and information available, you must be equipped 
with a MODEM. 

The Commodore PlusMMODEM connects your Plus/4 to these 
information services over telephone lines. With one of these modems, 
you can have access to computer services such as CompuServe and 
The Source. Commodore supports its own service called the Commo- 
dore Information Network, which is available through CompuServe. 
The Commodore Information Network (CIN) specializes in information 
for the Commodore owner, including current dealer lists, Commodore 
hardware and software tips, and a direct line to Commodore Customer 
Support. A wide assortment of programs is available on the Commo- 
dore User Database segment of CIN. including graphics, music, 
educational programs, utilities and games. 



21 



CHAPmt2 



USING 

THE 

KEYBOARD 

AND 

THE 

SCREEN 

• A tour of the keyboard 

• Special keys 



• Graphic keys 

• Programmable function keys 

• The HELP key 



22 



A 

TOUR 

OF 

THE 

KEYBOARD 




Most of the keys on the Plus, 4 keyboard are identical to the keys on 
a typewriter, bul each key can do more than a typewriter key. In Ihis 
section, you II learn how to use special keys like the O key and the 
cursor arrow keys. This section wtll show you the extra features of every 
key, including how to use the graphic symbols pictured on the fronts of — 
many of the keys. 

While we guide you on the tour of the PlusM keyboard, you should find — ' 
the keys and practice using them. 



23 



SPECIAL RETURN 

KEYS 



r i 



You have lo press the RETURN key at the end of each line of 
instructions you enter on your Connmodore PlusM keyboard. You might 
thinkof this key as an ENTER key because RETURN actually enters 
information and instructions into the computer, 

sHre-Ti 

This key works like the shift key on a regular typewriter. Your Plus/4 has 
two SHIFT keys and a SHIFT LOCK . which works like the shift 
lock on a typewnter. 

By pressing the shift key, you can get the graphic symbol on 
the right side on each graphics key when you are in upper-case/ 
graphics mode. 



2- 



Your Plus/4 is automatically in upper-case/graphics mode when you 
turn it on. In upper-case/graphics mode, all the letters appear upper- 
case without the SHIFT key. 

The SHIFT key pressed with a letter key gets upper-case (capital) 
letters when you are in upper/ lower-case text mode {the same as the 

SHIFT key on a typewriter). When in this mode, the letlers you type 
are in lower-case except when you use the SHIFT key 

NOTE: You can go back and forth between upper-case/graphics 
and upper/lower-case text modes by pressing the SHIFT and 
^'^■?^ l^ey at the same time. 

RUN/STOP j 

Press this key to break into a running program to STOP what your 
P!us/4 is doing. When the Plus/4 is running a program, pressing this 
key returns control back to you and the keyboard. 

When you hold down the SHIFT and RUN/STOP keys simul- 
taneously, ttie Plus/4 loads and runs the first program on a disk in 
the disk drive 



24 



J 



The 
Cursor ^J^y 
Keys 



It's easy to move the cursor quickly around the screen in any direction. 
Just press the cursor arrow key that points in the direction you want to 
go. Like all keys on the Plus/4 keyboard, each cursor key can repeat 
indefinitely while the key is held down. This automatic repeat function 
keeps the cursor moving until you release the key. 

NOTE: You can move the cursor over letters and numbers on the 
screen without affecting those characters. 



INST/DEL ' 

You can INSERT and DELETE letters and numbers from the line 
you are typing by pressing this key. When you press this key by 
itself, that character immediately to the left of the cursor disappears, 
and the cursor moves over to where the missing character was. You 
can use the cursor keys to go back to the middle of a line and then use 

DEL .; to DELete a letter. When you do this, the letter to the left is 
deleted, and the rest of the letters on the line move over one space to 
the left to close the gap. 

You can open up space lo insert letters and numbers by using the 

SHIFT nnd INST keys. Space opens to the right of the cursor: 
the cursor itself does not move. When you insert space in the middle of 
a line of letters, the rest of the line moves to the right. 

The INST/DELI key saves a lot of time when you wani to edit 

or change what you've typed. j 

CLR/HOME I 

This key serves three functions: HOME, CLEAR, and CLEAR 
WINDOWS, When you press this key, the cursor immediately moves to ■ 
the top left corner of the screen This is called the HOME position. The 
rest of your screen stays the same. If you hold down the SHIFT key 
and press CLR/HOME : . not only does the cursor move lo HOfvlE. 
but the screen clears All that remains on the screen is the blinking 
cursor at the top left corner of the screen. If you press this key twice. 



25 --^ 



n 



1 1 



any screen windows that you tiave set up are erased. Screen windows 
are work areas that you designate on part of the screen; there'll be 
more about them later. 

CONTROL.^ 

This key always works with another key. The SSISBSRSI^ key works 
like the SHIFT, key: you must hold it down while you press the 
other key, 

1 . As the COLOR KEYS section explains, pressing "'CONTROt 

and a color key allows you to choose ttie color of the text printed on 
the screen. 

2 You can pause a program that is PRINTing or LISTing on the 
screen by pressing GOHTROI. and the 8 key (press any key to 
resume program output). 

3 CONTROL IS also used with the BEVERSE ON/OFF and 
FLASH ON/OFF keys. 

In addition, some software programs Ihat you buy make use of the 
1: CONTROL key for their own special functions. 

Like the CONTROL key, the Commodore key works with other keys. 
It has lour functions: 

1 . When used with the shift., key, the 'ssSkM key lets you switch 
between upper-case/graphjcs mode and upper/lower-case 

text modes. 

2. When you're in either mode, the O key acts as a shift to let 
you type the graphics symbol pictured on the LEf^ front of each 
key. Just hold dov/n C» : , and press the graphic key you want. 






— , • 3. When you want to change the color you are typing in to one of the 

8 colors listed on the BOTTOM row of the face of the color keys, 
press . :fr ;' J and the color key you want, 

4. When you want to slow down a scrolling program display, hold 
down the O key. The display scrolling speed slows down 
\\ considerably. When you release the key, the screen scrolling 

resumes normal speed. (Hey, it can do something by itself!) 



The 
Color 
Keys 



[^-rn^A ,S,-ht <1 L^^S^i /Wn^ W^^ '.^rA L'^^bTtI >^^ 

You can change the colors of the letters, numbers, and graphics 
Symbols on the screen to any one of the 16 colors available on your 
Plus/4. It's simple to do: 

• If you want one of the 8 colors listed on the TOP row on the 
front of the color keys (like BLK for black), just hold down the 

CONinOL key and press the key with the color you want 
at the same time. 

• It you wani one of the 8 colors listed on the BOTTOfvl row on 
the front of the color keys (orange, for example). )ust hold 
down the O key and then press the color key with the 
color you want. 

Practice changing colors to make sure you understand how to do this. 
You'll notice that after you change the color, every letter and number 
typed AFTERWARDS is in the color you last chose, 

REVERSE ON 
REVERSE OFF 

Your Plus,''4 lets you print the reverse image of letters and numbers. 
In other words, if you are using black letters on a yellow background, 
you can use the reverse image keys to print yellow letters on a black 
background 

Here s all you do to get reversed images Press the control Key 
and the RVS ON key Now everything you type is displayec m 
reverse uniil you press the CONTROL and RVS OFF , the 

RETURN key, or the ESCapa Key and This returns you to 
typing normal (non-reversed) characters, 

FLASH ON 1| 
FLASH OFF " 

You can make ihe characters on you' screen flash continuously Jus! 
press CONTROL and the FLASH ON key to make whatever you 
type flash. Typing CONTROL and FLASH OFF , RETURN . or 
ESCape lets you type normal (non-flashing) characters again 



_J 



U 



n 



27 -^ 



r i 



GRAPHIC As we mentioned before, when you turn on the Plus/4, it is in upper- 
KEYS case/graphics text mode. When you're in this mode, you can type the 
full set of more than 60 graphics you see on the fronts of many of the 
keys, as well as all upper-case letters without using the SHIFT 
key- The SHIFT key lets you type graphics in this mode, instead of 
upper-case letters. 

There are two graphic symbols on each graphics key: 

• To print the graphic symbol on the right, hold down the SHIFTS 
key while you press the appropriate key. 

• To print the graphic symbol on the left, hold down the & key 
while you press the selected key. 

You can create pictures, charts, and designs by printing graphics 
side-by-side or on top of each other, like building blocks. Try printing 
some of the graphics keys to see how they work. Chapter 7 explains 
more about graphics. 

You can switch between upper-case/graphics mode and upper/ lower- 
case mode by pressing the SHIFT and Cf keys at the same 
time. In either mode, type BASIC commands without holding down the 
t SHIFT key. 

In this mode, you can type upper- and lower-case letters, just like a 
regular typewriter. {You will have to shift for upper-case letters.) You 
also can use the graphic characters on the left front of the keys, which 
print as in upper-case/graphics mode; hold down 0" and press 
the graphic key. The left side graphics are ideal for creating charts, 
graphs, and business forms. 

, ESCAPE 

The Escape key lets you perform many special screen edit- 
ing functions, including functions utilizing the windowing capability of 
the Plus.'4. Windows are areas of the screen (defined by you) that may 
be used as work space without affecting the rest of the screen, The 

Escape key can perform several window editing functions, 
as well as many other regular uses, such as inserting, deleting, 
and scrolling 

The Escape key is typically used with standard alphabet keys. To 
activate a function, press the ESCape key followed by one of the 
keys listed below: 



28 



A Automatic insert mode ^i 

B Set the bottom right corner of the screen window 

(at the current cursor location) 

C Cancel automatic insert mode 

D Delete current Itne I , 

I Insert a line ■■ 

J Move to the beginning of the current line 

K Move to the end of the current line 

L Turn on scrolling 

M Turn off scrolling 

N Return to normal screen display size "" 

Cancel insert, quote, reverse, and flash modes 

P Erase everything up to the cursor position on the current line — 

Q Erase everything up to the end of the current line from 

cursor position __ 

R Reduce screen display 

T Set the top left corner of the screen window |i| 

V Scroll screen up 

W Scroll screen down ^ 

X Cancel the escape function ■ 

Special Symbols |H 

The Plus/4 Keyboard also contains special symbols not found 

on many typewriters, or even on most computers. These special , 

symbols include the English pound sign (C). pi (tt), greater and less 
than signs (< >), brackets (I |). and arrows (t). These special sym- ■ 

bols keys are used in programming your Plus/4. 



»4 

Mi 



29 



PROGRAMMABLE 

FUNCTION 

KEYS 



n 



: I 



. 1 



F1/F4 



^i 



FI/F5 



-> ti""° ^ ^ 



HELP/F7 



3 



The four keys at the top of your keyboard are special function keys thiat 
let you save time by performing repetitive tasks with the stroke of just 
one key. 

You can display what each key does by typing KEY and pressing 
RETURN. 

The screen displays: 

KEY 

KEY 1, "GRAPHIC" 

KEY 2,"DLOAD"*CHRS{34) 

KEY 3 ."DIRECTORY" + CHR$(13) 

KEY4,"SCNCLR"*CHR$(13) 

KEY 5,"DSAVE"*CHR$(34) 

KEY6,"RUN"*CHRS{13) 

KEY7,"LIST"-CHR$(13) 

KEY 8,"HELP" + CHR$(13) 

Here's what each key does: 

KEY 1 enters one of the GRAPHICS modes when you supply the 
number of the graphics area (e.g., GRAPHICS 2, which is 
split screen, high resolution mode) and a return On 
computers with built-in software, KEY 1 is redefined so that 
pressing it activates the software package. 

KEY 2 prints DLOAD " on the screen. All you do is enter the 
program name to load a program from disk and hit 
: RETURN insteadof typing out DLOAD yourself. 

KEY 3 lists a DIRECTORY of files on the disk in the disk dhve. 

KEY 4 clears the screen (even in one of the graphics modes.) 

KEY 5 prints DSAVE "on the screen. All you do is enter the 

program name to save the current program on disk and 
press RETURN 

KEY 6 RUNs the current program. 



30 



KEY 7 displays a LISTing of the current program. ^ 

KEYS (the HELP key) highlights errors in program siatements 

m flashing print. u-i 

To use one of these functions, just press the appropriate function key. 

You need to use the SHIFT key to get FUNCTIONS 4, 5, 6, and 7. "^ 

You can redefine any of these keys to perform a function that suits ^ 
your needs. Redefining is easy, using the KEY command. You can 

redefine the keys from BASIC programs, or change them at any time , 

in direct mode, (The new definitions are erased when you turn off your — ' 
Plus 4.) You can redefine as many keys as you want and as many times 

as you want. hd 



m 
m 
m 



31 



THE 

HELP 

KEY 



FHiLP 



When you make an error in a program, the Plus 4 displays an error 
message to tell you what you did wrong. These error messages are 
further explained in Section 4 of the Plus/4 Encyclopedia in the second 
half of this manual 

You can get more assistance with errors by using the H£LP key 
After an error message, press HELP to locate your error. When you 
press ""hMJP . the line wilh the error is displayed on the screen with 
the error flashing on and off For example. 



7SYNTAX ERROR IN 
LINE 10 



Plus 4 displays this 



HELP 

10 FRONT ■'COMMODORE 
COMPUTERS" 



You press HELP 



Plus 4 displays this 
with your error 
flashing 



32 



y 

m 



CHAPTERS 



USING 
SOFTWARE 

• Introduction 

• Built-in software 

• Cartridges 

• Cassettes 

• Diskettes 



33 



_J 



INTRODUCTION "'"'^^ family of software available for your Plus/4 is growing quickly. Your 
dealer can Keep you up-to-date on new products and inform you about 
the features of software that s currently available. 

Your Commodore Plus/4 can use software on CARTRIDGE. CAS- 
SETTE TAPE and DISKETTE form, available from your Commodore 
dealer. All you do is load them into your Plus/'4, You can also create 
and store your own programs on cassette tapes or floppy disks. 



BUILT-IN 
SOFTWARE 



Your Plus 4 IS equipped with builtnn software packages These are 
programs built into the Plus.'4, turned on by pressing the appropriate 
FUNCTION key. Your Pius'4 built-in software makes your computer a 
word processor, database, spreadsheet and graphics machine. A 
built-in package is ready to use whenever you power up your com- 
puter. When you turn on your Plus/4, the screen message tells you 
which packages are available and what function key to use to activate 
them. Also you can use the KEY command to see the function key 
definitions. If there is function key software built into your Plus 4. the 
definition for KEY 1 will be: SYS XXXXX:package name Just press 
FUNCTION KEY 1 and press RETURN to activate the program 



iJ 



m 
m 
m 



u 



34 



CARTRIDGES 

Loading 
Cartridges 



n 



Commodore prodiices a full assortment ol cartridge software for 
your PluS'4, There is a variety of personal, educalion, and business 
programs, as well as exciting games available on cartridge for your 
Plus 4 Follow these steps to use cartridges: 

STEP 1 Turn OFF your Ptus/4. 



IMPORTANT: YOU MUST TURN OFF YOUR COMPUTER 
BEFORE YOU INSERT OR REMOVE CARTRIDGES, IF 
YOU DON! YOU MAY DAMAGE THE CARTRIDGE AND 
THE COMPUTER 



, J 



STEP 2 Hold the cartridge with the label facing UP, and insert 
the cartndge firmly in the cartridge slot into the back of 
your computer. 




STEP 3 Turn ON your Plus/4. 

STEP 4 Begin the game or program according to the instructions 
that come with the software. A cartndge program starts 
immediately, while function software starts after pressing 
the function key. 



35 



CASSETTES 

Loading 

Cassette 

Tapes 




>*• 



a 



A variety of software products for the Plus/4 is available on cassette 
tape. These cassette tapes are similar to the music cassettes that you 
play on your tape deck or stereo. Computer tapes run in the Datassette 
tape recorder, available from your Commodore dealer. 

You can also use cassette tapes and the Datassette to store programs 
you write yourself. The next section explains how to save programs 
on tape. 

The steps for loading tape are the same whether you are using 
prerecorded software or programs you saved yourself. 

STEP 1 Insert the cassette into your Datassette and close the door. 

STEP 2 Rewind the tape to the beginning by pressing the REWIND 
button on the Datassette, 

STEP 3 When the tape is rewound to the beginning, type LOAD and 
press the BETDRN 7 key. The computer responds with the 
following message: 

PRESS PLAY ON TAPE 



STEP 4 Press the PLAY button on the Datassette. The screen goes 
blank as the Datassette starts When a program is found, 
the screen displays this message: 

FOUND "program name" 

STEP 5 Press the Commodore key to load the program that was 

FOUND, If there is more than one program on the tape, and 
the program the Plus/4 found isn't the one you want, press 
the space bar to keep searching. 



m 

ri 



36 



When the program is loaded, the word READY appears. If you want to 
stop the loading before it's complete, press the RUN/STOP key. 
After the software is toaded, type RUN to start the program. You can 
also LIST the program or change it, if it is a BASIC program. 

NOTE: To LOAD a specific program on the tape, use the LOAD 1 
"program name" form of the LOAD command. -■*. 

SavinO when you write a program and want to save it on cassette tape, follow 
Programs '^ese steps: 

On STEP1 Type: 

Cassette 



Tape 



SAVE "program name" 

The program name you use can be anything you want, 
but can be no more than 16 letters and/or numbers long. 

STEP 2 Press the ,.;KETURN key. The computer displays 
this message: 

. 1 

PRESS RECORD AND PLAY ON TAPE 

STEP 3 Press the RECORD and PLAY buttons on your Datassette. 

. The screen goes blank. When your program is saved, the 

word READY appears on the screen. 

— Examples of SAVE Commands for CasseHe Tape: 

_^ SAVE "MYJOB" 

SAVE "STEST" 

NOTE: When saving a program onto a cassette tape, always 
—^ be aware of where the tape is positioned. !n particular, becare- 

' ^ ful not to save a program at the absolute beginning of a tape, 

_ since many tapes have magnetic leaders, which will not record 

information. Thus, part of the program would not be saved. 

"^ When LOADing or SAVEing a program, if you decide to stop before 

It's finished, you must press the RUN/STOP key first. After pressing 
— ^ RUN/STOP on the keyboard, then press the stop button on the 
• ■* Datassette. 

"■ 37 





This name is the 
specific name of the 
program being saved 







DISKETTES 

Loading 

Programs 

From 

Diskette 




Disks are last and easy to use. Be sure to handle your disks and your 
disk drive carefully. Disks may be referred to as diskettes, floppy disks, 
or floppies interchangeably: they are all the same thing. 
The steps are the same for loading all disks: 

STEP 1 Make sure that your disk drive is ON. 



STEP 4 



STEPS 




STEP 2 Insert the disk into the disk drive. The label side of the disk 
must face up. Insert the disk into the opening so that the la- 
beled end goes in last. Look for a little notch on the side of — • 
disk (it might be covered with a sticker). This notch should 

be the left side as you put in the disk, assunning that you're 

facing your disk drive. Be sure the disk is in all the way, 

STEP 3 Close the protective door on the disk drive after you insert .. 
the disk. 



Type: 

DLOAD "program name" 



d 



specific name of the 
program to be 
LOADed 



To save time, you could press FUNCTION KEY 2 and type in ' 
the program name and the second quote marks. 

Press the RETURN key. The disk spins and your 
screen says; 



38- 



SEARCHING FOR PROGRAM NAME 

LOADING 

READY 



Headering 

A 

Diskette 



STEP 6 Your software is ready to use. Now type RUN and press ttie 
RETURN key to start the program. 

If the red light on the disk drive blinks after the DLOAD is finished, 
something went wrong, Type: 

?DS$ (and hit return ) 

to find out wfiat went wrong. 
Examples of DLOAD commands: 



LOADS the 1st 
program on the disk. 
LOADS a disk 
program called 
MYFILE. 
LOADS the first 
programon tfiedisk 
that begins with the 
ietters SET 
LOADS the directory, 
a listing of all the 
programs on the disk 
in the drive, 

Headenng prepares a new BLANK disk for use. Any blank disk must 
be formatted before it may be used, by using the HEADER command. 

IMPORTANT: DO NOT HEADER A DISK THAT HAS ANYTHING 
ON IT UNLESS YOU WANT TO ERASE THE ENTIRE DISK. 
HEADERING ERASES EVERYTHING ALREADY ON A DISK. 



DLOAD'"" 
DLOAD "MYFILE' 

DLOAD "SET"' 

DLOAD "$" 



39 



The format for V^e HEADER command is: __i 

HEADER "disk riame", Udevice#, Ii.d.#,Ddrive# rj 



• Ttne name you use is the name of the entire disk. Give thie disk 

any name up to 16 characters, , : 

• Device # specifies v^^hich device for your computer (disk drive 

as opposed to Daiassette), and is usually number 8. 

— i 

• The id. is the letter I and any two letters and'or numbers, like 121 , 
IRS, etc. Give the disk any i.d. you want, but you should give ^ 
every disk a different i.d. to avoid confusion. 

• If you have a dual drive, add DO or D1 to identify the drive ^ 
number. If you have a single drive, you must use DO, 

m 

ARE YOU SURE? 

As soon as you press RETURN after typing the HEADER command, "^ 
the Plus/4 asks ARE YOU SURE? This is to give you a last chance to 
change your mind. — ' 

To header the disk, type YES or Y and press return If you : 

decide not to header the disk, type NO or N and press RETURN , ~^ 

Here are some examples of HEADER commands: ^ 

HEADER "LETTERS". US. 107,D0 |i| 

HEADER "FtNANCES", U8,IS3,D0 

Now that you know how to HEADER a disk, you're ready to use disks to „j 
write and save programs on your Plus/4. The first section of the Plus/4 
Encyclopedia has more information about the HEADER command. 

Savinn when you want to reuse a program you've written, be sure to SAVE it 

PrOOramS before you LOAD another program or turn off the Pius/4. If you don't, , 

rin you II lose the program. 

DiskGttB When you change a SAVEd program, you have to save it again if you — 1 
want to keep the new version. 

When you reSAVE a program, you are replacing the old version with -^ 



n 



. i 



the new one. If you want to keep both the old and the changed 
versions, you have to give the new one a different name when you 
SAVE it. 

Follow these steps to save a program on disk: 

STEP 1 Type DSAVE "program name". 

STEP 2 Press RETUHN . The computer displays this message when 
the program is saved: 

SAVING "program name" 

OK 

READY. 



. i 



Example: 

DSAVE "MYPROGB" 



The program name 
can be up to 16 
characters long 



; i 



THE 
DIRECTORY 
COMMAND 



n 



If the red light on the disk drive blinks after the DSAVE is finished, 
something went wrong. Type: 

?DS$ (and hit RETURN ) 

to learn what went wrong. 

When you SAVE programs on disk, the computer keeps a listing of all 
the files saved on that disk. You can display the listing as a table of 
contents to see what's on a disk by using the directory command: 

Type: DIRECTORY then press RETURN 
(or press FUNCTION KEY 3) 

As soon as you press .-RETURN . your Plus/4 displays every- 
thing on your disk. 
You can also display just part of the labia of contents: 



n 



DIRECTORY ' 'MY* " ' RETURN 



Lists every file on the disk that 
starts with the letters MY. 



41 



n 



n 



CHAPTER 4 



GETTING 
STARTED 



• Keyboard colors 

• Color and reverse printing 



• Some simple programs 



Correcting typing mistakes 



• Introduction to the Plus/4 screen 



More about PRINTing on the screen 



Screen windows 



, i 



. ) 



42 



INTRODUCTION The purpose of Ihis chapter is to begin to acquaint you with some of the 
characteristics and capabilities of the Plus/4, and how to take the first 
steps toward programming with your computer. 



43 



KEYBOARD You can change the color of the characters on the screen to improve 
COLORS '^eadability or !o find a color connbination you fike. To see how the differ- 
ent color characters look on your screen, try this 

STEP 1 Hold down the CONTROL key. 

STEP 2 Press the 6 key while you re holding the CONTROt '" 
key down , The cursor turns green 

STEP 3 Let go of CONTROL cind type some letters. Everything 
you type appears in green now. 



HOLD CONTROt ■ 


COLOR 


WITH COLOR KEY 


RESULT 


1 


BLACK 


2 


WHITE 


3 


RED 


4 


CYAN 


5 


PURPLE 


6 


GREEN 


7 


BLUE 


8 


YELLOW 



Using the ^-CONTROL- ' key with the number keys 1 through 8 allows 
you to choose Ihe colors shown on the top of each color key. 

Now hold down the O key. By typing on the keys between 

1 and 8, the cursor changes one of Ihe 8 colors printed on the bottom of 

each color key. All 16 colors can appear on the screen at the same time. 



holdSHB 


COLOR 


WITH COLOR KEY 


RESULT 


1 


ORANGE 


2 


BROWN 


3 


YELLOW-GREEN 


4 


PINK 


5 


BLUE-GREEN 


6 


LIGHT BLUE 


7 


DARK BLUE 


8 


LIGHT GREEN 



44 



COLOR Your Plus/4 can display numbers, letters and graphic symbols in the 16 —* 
AND cliflerent colors. You can also display these characters In reverse, with 
REVERSE 'f^s P''i'^3''y (cursor) and background colors reversed ^4 

rnlNTINti gj^p i Qigg^ you- screen by pressing SHIFT and ^ 

STEP 2 Hold dov^n the CONTROL l<ey and press the ||| 

RVS ON key 

^9 



STEP 3 Release the keys and hold down the space bar (the long 
bar at the bottom ot the keyboard), 

STEP 4 Hold down the space bar as long as you want. While you 

hold down the space bar, a line the same color as the letters 
on your screen should get longer. I( the line gets to the end 
of the row. it continues on the next row 

STEP 5 Release the space bar (but don'l press the 
BETURN key ) 

STEP 6 Hold down the CONTROL key and press one of 

the color keys (not a color that s already on your screen). 
As soon as you do this, the cursor will be the color of the 
key you pressed 

STEP 7 Hold the space bar down again, f^tow your Plus/4 will draw 
a line in the new color Continue changing colors with the 

CONTROL, or O keys and the color keys. 
Then hold down the space bar to make different colored lines 

STEP 8 Turn off reverse print by holding down CONTROL 
and pressing the RVS OFF key Pressing the 
RETURN key also turns off reverse printing. 

^0 



Try typing some letter in reverse. Just hold down CONTROL and 
RVS ON to turn on reverse, and then type whatever you want. Reverse 
letters make excellent headlines. You can also use them to highlight 



a 



— ^ 

45 



n 



n 



n 



special words and numbers. Try this: 



PRINT" Q COMMODORE H PLUS/4" 

1 \ 

Press CONTROL .; \ Press control 1 

and RVSONii and rvsoff 



Now try the same line, replacing reverse on and off witli FLASH ON 
and OFF: 



PRINT" H COMMODORE H PLUS/4" 

♦ \ 

Press CONTROL I \ Press CONTROL 1 

and FLASH ON and flash OFF j 



Bothi functions may also be used on the Plus/4 as part ol a 
program statement, 



46 



SOME 

SIMPLE 

PLUS/4 

PROGRAMS 



Type this program exactly as it appears here. Don't leave out the 
numbers at the beginning of the line, since they are the line numbers 
that tell the order that the lines of the program are implemented by your 
computer. Be sure to press the RETURN Itey at the end of each line 
you type. 



-I 



10 PRINT"PLUS/4" 



This line tells your 
computer to PRINT 
Plus.M on the screen 



20 GOTO 10 



RUN 



This line tells your 
computer to go bacl^ 
to line 10 and phnt 
Plus/4 again. 



This commands your 
computer to carry out 
what fhe 2 lines tell it 
to do. 



Press the RUN/STOP key to stop the program. 
Why did your Plus/4 print its name so many limes? GOTO tells your 
computer to go bacl<.toline 10 and PRINT Plus/4 again and again. 
This repetition is called a loop. 

Now type this: 

NEW RETURN 



The computer responds: 



READY. 



Here you tell the 
computer to forget 
the last program 
and get ready for 
a new one. 



You DON'T type this: 
your Plus/4 does to 
tell you It's READY 
for a new program. 



r i 



{g^ 



47 



10 PRINT"PLUS/4' 



Same line 10 as last 
time^ PRINT tells your 
Plus/4 to display 
everything between 
the quotes, 



20 COLOR 0,12 



This command tells 
the computer to 
change the color 
of the screen. 



RUN 



This time there's no GOTO loop in the program, so your orders are 
carried out just once. 



CORRECTING 

TYPING 

MISTAKES 



If you make a mistake when you're typing, there are several ways to 
make changes. 

1 . YOU CAN RETYPE A LINE anytime, even after you've RUN the 
program. The Plus/4 aulomatically replaces the old line with the 
new one when you press RETURN to enter the new line. 
The old line still appears on the screen, but the Plus/4 ignores it. 
When you have tv/o statements with the same line number, your 
Plus/4 uses only the last one entered For example, in a brief 
program using the COLOR command to change the color of the 
screen background, a mistake might occur 



10COKOR0.3 

20 PRINT ■'PLUS,:4" 

Press the return 
10 correctly: 

10 COLOR 0,3 



mistake 



■^ey to get to a fresh line, and just retype line 



RETURN 



Now the first line 10 is replaced by the second line 10. You can 
check this by typing LIST, which displays a line-by-line LISTing of 



48 



your program as It is stored In ttie computer's memory Whien you j 

LIST a program, all lines appear in correct order and the replaced 

lines don't appear: ^ 

LIST BStURN •' ^ 

The screen reads: 



u 



10 COLOR 0,3 

20 PRINT "PLUS 4" 

Replacing lines in a program is also a good way to experiment with 
your computer. When you replace a line, the new one doesn't have 
to be anything like the old line. For example, instead of correcting 
the spelling of COLOR, you can type this: 

^ space 

10 PRINT "TEN IS SIX " 

Now RUN the program and see what happens, 

2. YOU CAN ERASE AN UNWANTED LINE just by typing the 
numberof the line and pressing RETURN .The computer 
ignores the line even though it still appears on the screen. 
Type LIST to get the program LISTIng to make sure the line 
is gone fromi the program, 

10PRINT"TENISSIX" RETURN 

20 PRINT "PLUS;4" RETURN 

10 RETURN 

LIST RETURN 
20 PRINT "PLUS/4" 



YOU CAN EDIT A LINE, Use the cursor keys to move to the place in 
the line that you want to change. Now just type over what you want — « 
to change. Press RETURN when you finish. 



49 



- J 



NOTE: When working with numbered program lines, you don't 
have to be at the end of the line to press return . 
Your Plus/4 remembers the whole line even if you press 
RETURN in the middle of the line, 

10 PRINT "IT IS ONE O'CLOCK" 

It you want to change the lime to TWO, move the cursor to the 
OinONE- 

10 PRINT "IT IS BJNE O'CLOCK" 

And now just type TWO over ONE and press return 

10' PRINT "IT IS TWO O'CLOCK" jjg,j,^jp^.. 

NOTE: When you type a quotation mark after a PRINT statement, 
you enter QUOTE MODE. In quote mode, some keys work dif- 
ferently. For example, if you press the cursor-down arrow while 
you're in quote mode, the cursor won't move and you'll see a 
reverse Q printed on the screen. When you run the PRINT state- 
ment, the reverse Q isn t PRINTed; instead the cursor moves 
down. In quote mode, the computer assumes that everything 
you type is something you want to display or do later when 
you execute the PRINT statement. 

4. YOU CAN OPEN UP SPACES IN A WORD OR LINE with 
the INST key (get this insert key by holding down 
SHIFT while you press INST/DEL ). Hold the 
keys down until you open up as many spaces as you need. 
(Notice that the cursor stays in the same place while spaces 
open up to the right.)Then just type what you want to insert. 

10 PRINT "CORE" RETURN 

To change this to COMMODORE-Plus/4, move the cursor to the 
hyphen between the C and the and press the SHIFT and 

INST keys until enough space opens up. Don't bother to 
count out the spaces. You can just guess and then open up more 
if there aren't enough. 



10 PRINT "C ■ ORE" 

"* ^ cursor 

Now add the other letters: 

10 PRINT "COMMODORE" RETURN 

5. YOU CAN ERASE CHARACTERS AND CLOSE UP SPACE 
witli ttie DEL key (get this delete key by pressing 
{' INST/DEL ), This key erases characters or spaces 
imiTiediately to the LEFT of the cursor. 

10 PRINT "ATTERNOON SCHEDULE" RETURN ' 

You can change this to WEEKLY SCHEDULE by moving the cursor 
to the E in AFTERNOON, pressing the INST/del key three 
times, and typing WEEKLY 

10 PRINT "AFT B RNOON SCHEDULE" 

and press INST/DEL three times, ^ . ,.,^^„, ,, 

Type in WEEKLY to 

replace ERNOON 

10 PRINT " Q RNOON SCHEDULE" and press RETURN 

^ Now that you've experimented a little with your Plus/4, here's a pro- 
LiHIb Q^^*^ '° "'y '^^' *'" '^^® ^ '''''^ longer to type in. (Any experienced 
programmer will tell you that, it nothing else, programming can help 
you really improve your typing.) 



Longer 
Program 



FirsLclear the screen by holding down the SHIFT key while 
you press the CLR/HOME key This erases your screen. 
Then, clear out old programs from memory by typing NEW and 
pressing RETURN . 

Type in this program exactly as it appears. Remember to type in the 
line numbers and all punctuation marks. Use the tips for correcting 
mistakes if you type something incorrectly, Don't forget to press 
RETURN after each line. 

NOTE: Remember, you can stop a program by pressing the 
RUN/srrom-::- key. 



51 _v 



n 



NEW 



10 COLOR 1,8 



n 



20 PRINT ■ 'A FUNNY THING HAPPENED 



30 COLOR 1,3 



40 PRINT "ON MY WAY TO THE KEYBOARD 




50 COLOR 1,7 



Be sure 10 leave a 
space here 



w 



Be sure 1o leave a 
space here 



60 PRINT" 1 
70 GOTO 60 

RUN 



Get the hearts 
by holding down 
SHIFT 

while you press 
theS key 6 times 



After you STOP the program (by pressing the RUN/STOP, key), try 
typing LIST. When the program is displayed on your screen, recall the 
tips for correcting errors and try changing this program to make it say 
something more profound. 



. ) 



TIP: Want to slow down this program without stopping it? Just 
hold down the'S^j^S key. 

THE Try typing this program. (Don't forget to press RETURN after entering 
PLUS/4 each line.) 

TEXT 
SCREEN ^^ 



, i 



10 PRINT ■' • 



press 
andS 



SHIFT 



52 



20 GOTO 10 



RUN 



Now your screen fills with hearts. When the entire screen Is covered 
with hearts, press the , RUN/STOP key to end the program. 
This program shows you how iiig your Plus/4's screen Is 

Now type this program: 

NEW 



10 PRINT •'□■ 



press SHIFT and CtR/HOME 



20 FOR X = 1TO40 

30 PRINT'' » 
40 NEXT X 



press SHIFT and S 



RUN 



When you RUN this program, the first row on your screen fills completely 
with hearts. There are 40 hearts altogether, Since the row is full, you 
can see that there are 40 positions across the screen. Each position 
across the screen is called a COLUMN. 



Now type this program: 



NEW 

10 PRINT "□' 



press SHIFT and CLR/HOME 



20 FOR X = 1T0 25 

30 PRINT "♦■ 
40 NEXT X 



press SHIFT and 2 



53 



RUN 

When you run (his program, the first column on your screen fills with 
diamonds. There are 25 diamonds printed, but the first three disappear 
at the top of the screen because the word READY surrounded by two 
blank lines always appears at the end of the program. There are, then, 
25 rows. A little deductive logic tells you that your Plus/4 has 40 col- 
umns and 25 rows The Plus/4 has 1000 different positions on the 
screen for letters, numbers, graphic symbols, etc. 

NOTE: Sometimes you'll type a particularly long line on your 
Plus/4, such as this: 

10 PRINT "I LIKE YOUR TOUCH ON MY KEYBOARD. DO YOU 
COME HERE OFTEN?"' 

(Thai's quite a line— over 50 characters long!) 

You'll notice that as you type this, you run out of room on one row. 
But keep typing: the Plus/4 automatically moves on to the next row 
and continues printing there until your line is finished. You can type 
as many as 80 characters on one program line (up to two full rows). 

Now try RUNning this one line program. The message is printed on 
two rows. If your line is longer than one row. the Plus/4 lets it spill over 
to the next row. The Plus/4 considers the line ended when you press 
the RETURN key, not when you type to the end of the row. 
You'll get used to this as you use your Plus/4. 

Now type this program; 



NEW 



10 PRINT '• 9 

20 GOTO 10 
RUN 

When you RUN this program, you can see that its possible to tell the 
Plus/4 exactly where to PRINT something on the screen. 




leave a space on 
each side of the heart 




press 
andS 


SHIFT 



54 



SCREEN 
WINDOWS 




J 

J 
J 

J 
J 

Windows let you define a specific area ol tfie screen as your 

workspace Everything you type (lines you type, LISTings of pro- | 

granns, etc.) after setting a window appears within the window s 

boundaries, not affecting the screen outside the window area 

You can set up a window anywhere on the screen. — 

To set a window, follow these steps 

1. Move the cursor to the screen position you want as the 
top left corner ol the window. 

2. Press the ESCape Key, and then the letter T. — ■ 
3 Move the cursor to the position you want to be the 

bottom right corner of Ihe window __. 

A Press ESCape, followed by B. Your window is now set 

All screen output is confined to the 'box' you have defined. To cancel .._ 
the window, press the home key twice The window is then erased, and 
the cursor is positioned in the top left corner of the screen 



57 



n 



CHAPHR 

NUMBERS 

AND CALCULATIONS 




• Numbers and basic operators 

• Performing calculations 

• Using variables 



• Immediate mode 



• Numeric functions 



• Random numbers and other functions 



58 



_J 



NUMBERS 

AND 

BASIC 

OPERATORS 



You can use your Plus/4 like a simple calculator. Besides Ihe standard 
+ and signs, your Plus/4 uses the "sign for multiplication and the / 
sign tor division and fractions. (Computers use the ' sign instead of an 
X for multiplication because a computer can't tell the difference be- 
tween the letter X and the mathematical symbot x ) You can use these 
operators and numbers in direct mode (no line numbers) or in a pro- 
gram. Neither numbers or operators should be in quotes for your Plus/4 
to perform mathematical operations. 



BASIC MATHEMATICAL 




BASIC RELATIONAL 




M 


OPERATORS 




OPERATORS 






Addition 


+ 


Greater than 


> 


' 1 


Subtraction 


- 


Less than 


< 




Division and fractions 


1 


Equals 


= 




f\/lultiplication 


* 


Greater than or equal 


= > 


— ' 


Exponentiation 


T 


Less than or equal 


< = 








Not equal to 


oorx 


— 



FRACTIONS 

AND 

DECIMALS 



NOTE: Your Plus/4 doesn't accept commas as part of a number. 
For example, you must type 109401 instead of 109,401 . If you put 
a comma in a number, your Plus/4 thinks you mean two numbers 
(separated by the comma), so your Plus/4 would read 109 and 
401 instead of 109401. 

You can write a fraction like this: ,5 

or like this: '72 -M 1 Your Plus/4 is 

actually performing 
the division 



If you put a fraction in a PRINT statement, your answer is always 
returned as a decimal or whole number. For example 



PRINT 139 493 - 5 
5.28194726 



RETURN 



Here's an example that uses pi (3.14159256. . .), which represents the 
ratio of the circumference of a circle to its diameter. Use this value by 
just pressing the ;7key: 



PRINT 7T/374 
8.39998036E-03 



RETDRN'' 



59 



SCIENTIFIC 
NOTATION 



What did your Plus'4 mean by the E-03 part of the above answer'' 
Your Plus. 4 displays decimal numbers in the range -999.999.999 to 
999.999,999 in standard numerals, Numbefs beyond this range (with 
more than nine digits) are automatically displayed m scientific notation 
You can enier numbers in yourself in this form and your Plus/4 will read 
them with no trouble (certainly less trouble than you had converting 
them). Scientific notation is often useful, since this special notation lets 
your Plus/4 display large numbers in fewer digits. 

Here is how the number 1 98.505.478 would be written in scientific 
notation 



Only ONE digit IS 
shown to the left of 
the decimal point 



1 ,98505478E + 8 



This number is the 
number of digit 
places the decimal 
point is moved 



For a number less than one with several decimal places, the second 
number would be a - instead of a + . indicating that the decimal point 
IS moved to the nght- 
For example 

0003359 = 3.359E - 4 
Other examples- 



20 = 2E + 1 
105000= 1.05E ^5 
.0666 = 6 66E - 2 



the decimal point is moved 1 digit left 
the decimal point is moved 5 digits left 
the decimal point is moved 2 digits right 



60 



PERFORMING ^° perform a calculation, type PRINT and then the math problem. 
CALCULATIONS R^'^S'^ber not to put the problem in quotes. 
Type this program: 



NEW 

10 PRINT 1^2,2-1 

20 PRINT 2'2, 4/2 

RUN 

3 1 

4 2 



use the slash on the ^ kev 



For the first time. PRINT didn't prinl exactly what you typed in the 
statement. Instead, your Plus'4 solved the calculalions and PRlNTed 
the answers. All you have to do to use PRINT to calculate is omit the 
quotation marks. IMow try this. 



M 



NEW 

10 PRINT "200T 2010' 
20 PRINT 2 '3 
RUN 

2001 2010 
6 



one Space is left 
lor the answers sign 



Since the calculation in line 10 is in quotes, your PluS'4 just PRINTs the 
problem as if ii were regular text: exactly as it appears between the 
quotation marks. The problem isn't solved, and no space is left for the 
sign of the number 

Now move 'he cursor back to line 10 and change the line to this 



10 PRINT '■2* 3 H l-";2'-3-l 



don t forget the semicolon 



RUN 




ihis space is left foi 
the answer's sign 


2 3*1 


.», 






6 


the answer for line 20 
stays the same 





If you want lo both PRINT the problem AND solve n you have to type it 
twice: once in quotes and once out of quotes, like this 



n _ 



n 



IMMEDIATE you can put any calculation in a program, or get an immediate answer 
MODE ^y typing PRINT and the problem without a line number and pressing 
RETURN, like this: 



. I 



, i 



, 4 



. i 



PRINT 3-6 
-3 

PRINT 24,' (6* 2) 
3 

With numbers as well as with commands and text, when you don't have 
a line number before a BASiC statement, you don t have to type RUN to 
tell the computer to follow the instruction; it's in IMMEDIATE, or DIRECT 
MODE, Having a line number means the statement is part of a BASIC 
program: it's in PROGRAM MODE. Either way is acceptable. 

You can also include both a text statement in quotation marks and a 
mathematical problem to be solved in a single PRINT statement in 

immediate mode. 



PRINT "2 TO THE 3RD POWER 
EQUALS' 'la 1 3 



2 TO THE 3RD POWER EQUALS 8 



this arrow stands for 
exponentiation, get 
It by typing SHIFT 
ardO 



the message is 
PRINTed and then 
the problems solu- 
tion IS PRINTed 



I 4 



r 4 



ORDER '^^^ second example in the last section shows that you can perform 
fjr more than one calculation in one line Try typing this 

CALCULATION print 200-50 5 

Is the answer what you expected'' Try this 

PRINT (200-50) 5 

Your Plus/4 always performs calculations in a certain order. Problems 
are solved from left to right: within that general rule, some types of 
calculations are solved first. The order which your Plus.'4 evaluates 
expressions is called the order of precedence of operators 



62 



FIRST: Your Plus/4 checks for negative numbers (not subtraction, — ' 
just negative numbers). 

SECOND Your Plus/4 solves any exponents. 

THIRD: Your Plus/4 solves all multiplications and divisions, from left — - 
torigtit. 

FOURTH: Your Plus/4 solves additions and subtractions, from left — ' 

torigliit, 

i 

NOTE. Your Plus/4 always solves any portion of the problem 
surrounded by parenlfieses first You can even pu! parentheses — ■ 
within parentheses; 36* (12 t (A/ 3)) Thecontentsof the inner- 
most parentheses are solved first. , 

Sometimes it's a good idea to put negative numbers in parentheses 

for clarity. For example, if you want to multiply 45 by 5, type it like this 
45*(-5). Your Plus/4 can understand with or without parentheses. 






63 



n 



USING The example 36*(12 + (A/'3)) shows one of the most powerful features 
VARIABLES °' ^ computer When we used a letter instead of a number \n a mathe- 
matical problem, we used a VARIABLE, A variable represents a value; 



r^ 



i i 



10A = 3 

20 PRINT "TOTAL; 



;A'-4 



If you RUN this program, the screen result Is; 

TOTAL, ^2 

There are three types of variabfes you can use; 



SAMPLE 
EXAMPLES VALUES 



real (decimal) X. AB, T4 


23,5, 12, 


or whole numbers 


1.3E + 2 


whole numbers X%, Al% 


15, 102,3 


letters, numbers, X$, MS$ 


•TOTAL;', 


and all other 


■'DAYV, "CBM 


characters 




in quotes 





TYPE SYMBOL DESCRiPTION 

Floating 
point 

Integer % 

Text string S 



Every time you want a variable to be an integer variable, the symbol 
for that variable would include the % sign, A variable that contains text 
MUST end with a S as partof the variable. If it doesn't have that symbol, 
your Plus/4 considers it a floating point number, A vanable without 
either of the symbols (% or $) is read as a floating point number (a 
"regular' number) Integer variables are a subset of floating point vari- 
ables: they are numbers with no decimal places 

Always use the rjghl variable type. If you try to do something like assign 
a word to an integer variable, your program won't wort^. This program 
shows you what variable can or can't be used in a given situation, and 
you can find out what happens when you try out different types of data; 

10 REM THIS PROGRAM NEEDS NUMERIC DATA 

20 PRINT "ENTER A NUMBER" 

30 INPUT X% -* 



X% 



40 PRINT "NICE GOING, ACE ! ' ' 

50 PRINT "I READ YOUR NUMBER AS 

Try to enter these values and see what happens 

ONE FIFTH 

-043 

10 



this is the variable 
to be input 



64 



NUMERIC Included in your Plus/4 BASIC 3.5 language are numeric functions, 
FUNCTIONS w^'<^*^ 3''s lil^e the advanced calculations found on most scientific cal- 
culators (such as sine, cosine, tangent, etc ) 

Most of the functions can be used by typing ttie name of tfie function 
and the number to be operated by the formula in parentheses, like this, 

FUNCTION(X) 

For example, to find out the sine of a variable, you would type 

PRINT SIN{X) 

with X as any number you want to input. 

You could also include one of the functions in a program tine, as the 
following example shows. 



RANDOM 

NUMBERS 

AND 

OTHER 

FUNCTIONd 



10FORX-1TO5 

20 PRINT "THE SQUARE ROOT OF" 

30 NEXT X 



X;"IS";SQR{X) 



There is a complete listing of the numeric functions in the BASIC 3.5 
Encyclopedia. Some of the more complex functions are explained in 
the following paragraphs. 

Selecting a random number is like taking 10 pieces of paper, writing a 
number from 1 to 10 on each piece and putting the 10 pieces o( paper 
into a hat and drawing one piece of paper. The number chosen is a 
RANDOM number. The number is put back into the hat. and another 
number is drawn. Each time a number is drawn, it is put back in the hat. 
keeping the pool o1 possible numbers the same. When a number is 
selected . there is no way of knowing what number is going to come up 
next, but you do know that the number will be between 1 and 10 This is 
the basis of RANDOM NUMBERS 

Random numbers are extremely useful in programming, providing the 
element of chance or (obviously) randomness. Random numbers usu- 
ally have a range, meaning theres an upper limit and a lower limit to 
(he numbers you can draw. In the hat example, the range of numbers is 
1 to 10. The lower limit is "1 ' and the upper limit is" 10", which means 
that any number from 1 to 10 can come up randomly each time a new 
number is selected. 



65 



Lei's examine how your Pius/4 Inandles random numbers, and some 
o1 ttie Ihings you can do witli ttiem This program generates five com- 
pietely random numbers 

10FORX=1 TO 5:PRINTRND(X):NEXTX 

These random numbers are ali rather complex, with several p;aces 
on the right side of the decimal point . . but most uses for random 
numbers require whole numbers You can make your numbers come 
out as whole numbers (without decimal places) by using the INTeger 
function, which cuts off all the digits on the right side of the decimal 
point. The following gives you a formula for generating random num- 
bers in any range you want. You can use this formula almost anywhere 
you would use a variable or number in your program 

INT(range'RND(l)) lower limit 

The INT command tells the computer to cut off any decimal places and 
only give you whole numbers like 1, 45, or 320, instead of numibers like 
1 .223, 45,6677, or 320,59, Whole numbers are easier to work with when 
using random numbers. 

Lower Limit in the formula refers to Ihe lowest number you want the 
computer to choose from 

Range is how many numbers are in the total group. 

For example, if you want to choose a random number from 1 to 5, 
the lower limit is 1 and the range is 5. If you wani to choose a random 
number from 15 to 20, the lower limit would be 15 and the range is 6, 
because you are choosing from a pool of 6 numbers. If you're choosing 
numbers from 2 to 100. the lower limit is 2 and the range is 99. Now lets 
Iry out a program: 

10 PRINT INT(5-RND(1)) - 1 

Type RUN and press RETURN RUN the program a tew t mes 
Each time you run the program, you get a random number from 1 to 5, 
Now let s prini 15 random numbers, wilh the lower limit 1 and the range 
5 nole that all 15 numbers chosen are selected at random from 
between 1 and 5: 



66 



J 



10 FOR X=l TO 16 sets loop for 15 times ,. 

20 PRINT INT(5-RND(1)) - 1 ■ 

30 NEXT X 

selects RaNDom |[| 

number 

m 

Type RUN and press RETURN. 

An effeclive way to use this formula is to make it into a user defined j 

function. User defined functions are extremely useful in matfiematical 
calcuiations, and extremely easy to tmplement using your Plus'4 User 
defined functions allow you to program a formula, and ttien let your 
Plus;4 plug in values to be calculated. Tfiis can be used for many dif- 
ferent purposes Section lOof the Encyclopedia section contains a _J 
listing of matfiematical function derivatives wfiicfi can be used to 
define functions _J 

Here is a statement utilizing tlie user defined function for generating 
random numbers: hA 

10DEFFNR(X) = INT{X-RND(1)) - 1 Ig 

This gives us random numbers in the range from 1 to X. FNR is the 

name of the function defined by this statement. *^ 

EXAMPLE using a defined function; H 

10DEFFNR(X) = INT(X'RND(1)) + 1 ^ 

20 DO * 

30 COLOR 1,FNR(16), 5: REM PICK A COLOR FROM 1 TO 16 
40 PRINT "THE SEARCH GOES ON" .,-• 

50 LOOP 

Using the defined function saves memory space when you use the ' 

function more than once, and makes your programs easier to read 

and understand. — ' 



67 — 



n 



CHAPTER 6 



BEGINNING 

BASIC 

PROGRAMMING 



• Introduction 



• Programming modes 



Input/Output statements 



Control statements and loops 



• Conditional statements 



Subroutines 



REMarks 



, 4 






Up until now, you may or may not have understood exactly what was 
going on in the programs that introduced you to some of the capabili- 
ties of your Plus/4. This chapter will explain some of the BASIC com- 
mands that were used in those programs. This chapter focuses on 
some of the more often used BASIC statements that you will need to 
construct your own programs. At the end of this chapter we will touch 
on some programming techniques. This chapter will give you a quick 
introduction to programming, but it is still an introduction. To really 
learn to program, we suggest you ptck up a gooct book on BASIC at 
your local bookstore (See the bibliography in Section 14 of the Ency- 
clopedia for suggestions ) There are many versions of BASIC, each a 
little different. Your Plus/4 is equipped with an advanced version of the 
BASIC language called Commodore BASIC 3.5. 



m 
m 

M 

li 
m 
m 



a 



69 — 



PROGRAMMING Your Plus,4 gives you two ways to use BASIC staiements and 

MODES commands: in direct mode and indirect mode. Direct mode is often 
referred to as immediate mode, and Indirect mode Is also known 
as program mode. 

DIRECT, or IMIVIEDIATE MODE, as the name implies, executes state- 
ments and commands immediately {as soon as you press RETUHNi 
after typing in a command). You do not type line numbers wtien using 
commands or statements in direct mode You omy type tfie command 
or statement and press Ihe RETtJUN key. This mode is used if you 
want your computer to perform calculations and give you an immediate 
result. Commands sucfi as LIST SAVE, LOAD, VERIFY and RUIM are 
usually used in direct node Most (but not all) BASIC statements work 
in direct mode 

INDIRECT or PROGRAM MODE, allows you to organize a series of 
BASIC statements into a sel of instructions ttnat will be performed In 
tfie order that you decide. Each of the lines in the program has a line 
number which tells the computer to execute the lines in a certain 
order. You ve already seen several examples of program mode in 
Chapter 4 Remember thai when you use program mode, you must 
press RETtmN loenter each line of the program into the mem- 
ory of your Plus.'4 If you don t press RETURN . and justgo tothe 
next line, the line you typed has not been entered. Once the program 
IS in memory, nothing will happen until you enter the RUN command. 
The RUN command teils the Pius/4 lo execute the program starting 
wilh the lowest numbered line. 

Lines are most often numbered by tens, since you II frequenlly have 
to add lines in different places in the process of writing a program. 
You could, if need be, add nine new lines between line 10 and line 
20 in a program. However, your Plus/4 features a BASIC command, 
RENUMBER, that allows you to add new lines and change the existing 
line numbers. This saves a lot of confusion that often occurs when 
changing and rearranging lines 



70 



INPUT/OUTPUT li^pul'Dutput (I/O) siatements are used in programs lo communicate 
STflTFMFNT<; ^'"^ ^^^ person RUNning the program. Before the program is run, if all 
alHIcmcnio (f^g data for the calculations is available, there is really little need for 
input statements. It is often more useful if the computer can get data 
from the person RUNning the program (we II call him or her the pro- 
gram user). Programs are much more versatile if the data is not "set in 
stone ■ before running them. Output statements can be used by the 
computer to tell the person running the program the answers tfiat the 
computer has calculated. Obviously, output statements are vital: there 
would be little sense in RUNning a program that had no output state- 
ments. (Kind of lii<e a tree falling in a forest with no one around to hear: 
does it make a sound? Does it matter?) 

Advanced programmers also use I'O siatements to communicate with 
devices Instead of with the program user. You ve probably done this 
yourself, but not in a program — when you used LOAD or SAVE with your 
Datassette or Disk drive, LOAD is basically an input statement since 
the Plus 4 gets data (your program) from your Datassette or disk 
drive while SAVE is an output statement, as the Plus 4 sends data to 
those devices. 

In this introduction to f'O statements, we will limit ourselves to a few 
of Ihe most important ones, the ones that you II need immediately. 
They are PRINT, INPUT GETKEY, and READ:DATA, PRINT is an 
output statement, while the others are input statements 
(Remember that all BASIC 10 statements can be found in the BASIC 
Encyclopedia at the end of this book,) 

Statement name: PRINT 

Format: PRINT "text in quotes" or variables or numbers 
or calculations, etc. 

You have used the PRINT statement often in programs in earlier chap- 
ters. From that, and from the format example above, you can see that 
PRINT is a very versatile statement. You can use it to PRINT out mes- 
sages, pictures made out of graphic characters, perform calculations, 
display the value of a variable, and more. Since the PRINT statement is 
used so often, it pays to learn to use it well. 

Use #1 Text Display 

Suppose in your program, you want to inform the user that his or 
her checking account balance is negative, or that purple lizards are 

71 



^J 



noi allowed in the control room. The easiest way would be to PRINT 
^ your statement as a text string. Text strings are printed out exactly as 

you type them in They must be surrounded by double quotes (" "). 
For example: 

' '' 100 PRINT "YOU ARE BROKE!-' 

~" would tell the user that there is no money left, while 

_^ 150 PRINT "YOU CANT BRING YOUR FRIEND INTO THE 

CONTROL ROOM" 

__ could be used in the second example. 

, i 

Whatever appears between the quotation marks is known as a literal. 
— • because it is PRINTed exactly as it appears It doesn't matter whether it 

IS words, letters, numbers, punctuation marks, etc 

~^ Certain keys, like the cursor and color keys, act differently when used 

in text strings. Instead of changing the color or moving the cursor when 
— ( you type the key. a reverse character is printed in the string. When 

^ ' theprogramisRUN.thecharacter IS translated into what you wanted 

_ typed in the first place. This lets you clear the screen, change the color 

your are PRlNTing in, move the cursor, all within your program. For 
example, try this: 



.1 



r i 



10 PRINT" SHIFT CEKTHONffi CONTOOE" 3 TESTING, 

CRSR-DOWN_ CONTROL 7 TESTING" 

Remember to type the following keys simultaneously when you use 
the SHIFT and CONTROL keys The reversed symbols are the signals 
to the computer that teils it to perform the dear screen, color change 
or move the cursor. 



Use #2 Printing Numbers anij Calculations 

. \ PRINT can display the answer to a calculation made within the print 

statement. (SEE NUMBERS and CALCULATIONS). The Plus/4 per- 

~~ forms the operations needed to get the answer, then displays it on 

the screen. For example. 



100 PRINT 58* 15,23,45 + 1000-45'{4-3) 

prints 
870 23 1000 



72 



This gets more interesting when variables are also used. User input — i 

can be displayed, and earlier calculations saved in variables can also 

be PRINTed out, or even used in additional calculations ^ 

Examples: 

m 

TYPE 

lOR-10 ■ 2: N= R-5 " 

20PRINT"RIS";R;" ANDNIS";N .^. 

30 PRINT "BUT R TIMES 2 IS":R'2 ■ 
40 PRINT "AND N MINUS 2 IS";N - 2 

U 

Normally, after each PRINT statement, the cursor automatically goes 

to the beginning of the next line You can override this by putting a . : 

semicolon I:) after the PRINT statement like this ^ 

200 PRINT "THESE TWO SENTENCE PARTS WILL BE ", 11 
210 PRINT "PRINTED ON THE SAME LINE" 



Statement name: INPUT 

Format INPUT optional message :variable to be input 

The INPUT statement lets you get data from the program user through 
the keyboard, and use it in the program. The optional message lets you 
tell the user exactly what you are asking for: the message is printed 
when the INPUT statement is executed, along with a question mark 
Then the Plus- 4 waits for the user to type an answer, followed by press- 
ing the ""RETURN" key. The input from the user is placed in a 
variable. You can either get a string from the user by using a string 
variable (AS, for exannple). or a number by using a numeric variable 
The INPUT statement can only be used tn program mode. 

Examples: 

TYPE 

10 PRINT "WHAT IS YOUR NAME" ; i 

20 INPUT AS 

30 PRINT "I AM PLEASED TO MEET YOU":AS;"." I 

40 INPUT"HOW OLD ARE YOU";AG 

50 PRINT AG; " IS A BIT OLDER THAN I AM." 

RUN 



73- 



Siatemeni name; GETKEY 

Format ; GETKEY variable to be input 

GETKEY IS another way for you to enter data while the program 
is being RUN. The GETKEY statement accepts only one key at a 
time. Whatever key is pressed is assigned to the string variable 
you specified in the GET statement (AS. for example). GETKEY is 
useful because it allows you to enter data one character at a time 
without having to press the RETURN: key after each character. 
The GETKEY siatemeni may only be used in a program 

Example of GETKEY in a program: 

1000 PRINT "PLEASE CHOOSE A, B, C, D, E, OR F" 
1010 GETKEY A$ 

Statement Name: READ/DATA 

Format: READ variables to be input 
DATA data items to be read 

The READ/DATA stateirients are used as a convenient way to assign 
values to variables. You can think of Ihe READ statement as an INPUT 
statement that asks the Plus.'4 for the data, rather ihan the user The 
data is (natufaily enough) kept in DATA statements. When the P,lus,'4 
executes a READ statement, it looks at the next data item in the DATA 
statement, and assigns it to the variable in the READ statement. 

The READ statement is always used with a DATA statement. A DATA 
statement is just a line of data (words or numbers) in a program. The 
READ statement is used to assign those values to variables. (For each 
variabie listed in the READ statement, your Plus.M "reads" a value from 
the DATA line for that variable) A DATA statement is not executable 
and can appear anywhere in the program. The thing to rememt)er 
about the READ statement is that the variable type must be the same 
as the type of data available in Ihe DATA statement (number vanables 
for numbers, text vanables for texl) Otherwise, a TYPE MISMATCH 
ERROR occurs. 

Example 

10READA$.B$.C$,D$,E$ 

20 PRINT A$: PRINT B$: PRINT C$ 

30 PRINT D$: PRINT E$ 



74 



40 DATA GROUCHO, HARPO, CHICO 
50 DATA ZEPPO, GUMMO 

The computer responds with; 

GROUCHO 

HARPO 

CHICO 

ZEPPO 

GUMMO 



75— 



CONTROL 

STATEMENTS 

AND 

LOOPS 



n 



It would be pretty boring if your computer coutcl only execute program 
lines in order. The computer could only start at the beginning and go 
through each step m order until the end of the program. This would 
lead to very long programs; if you wanted to do the same thing twice 
(like PRINT ■■HELLO), you would have to duplicate the program lines. 
With a small example like PRINTing HELLO, this doesn't make a lot of 
difference, but it could become difficult in larger programs This is why 
computers have control statements Control statements tell the com- 
puter to ignore the normal order of the program lines, and go to another 
line regardless of the sequence. The PluS'4 has several varieties of 
control statements unconditional (like GOTO) which always transfer 
control: counting statements (like FOR/NEXT) which transfer control 
a specified number of times; and, for you structured programming 
fans out there, DO.'LGOP. 

Statement Name: GOTO 

Format:GOTO line # 

GOTO tells your compuier to immediately go from the current line in 
your program to the line number specified in the GOTO statement. 
For example, if line 20 reads GOTO 40. your Plus/4 would jump to 
line 40. skipping any statements between 20 and 40. 

Example using GOTO statement in a program: 

TYPE: 

10 PRINT "A PENNY SAVED IS BETTER THAN NOTHING" 
20 GOTO 10 

The computer responds by printing the message in line 10 again and 
again, until you press the STOP key. like this: 

A PENNY SAVED IS BETTER THAN NOTHING 
A PENNY SAVED IS BETTER THAN NOTHING 
A PENNY SAVED IS BETTER THAN NOTHING 



BREAK IN 10 
READY. 



iyou press the 
STOP key 



This print statement will continue ■forever'. Every time your PIus.'4 gets 
to the GOTO in line 20 it goes back to line 10. This is called an INFINITE 



76 



LOOP in computerese. While you might want to do this, usually you 
want to repeat only a certain number of times, or until something hap- 
pens That IS why the FOR/NEXT and DO/LOOP statements are avail- 
able in BASIC 

GOTO can also be used in direct mode, GOTO line # will start the 
program at the line you specify, while keeping the variables the same 
(instead of clearing them as RUN does). 



Statement Name:FOR'NEXT 

FormaiFOR variable = siart value TO end value 
some BASIC statements 
NEXT variable 

The FOR NEXT statements let you create a loop that will repeat a 
certain number of times The program statements between the FOR 
statement and the matching NEXT statement are repeated in the loop. 
The variable in the FOR statement acts as a counter It is initially set at 
the start value you supply. Then, the program lines after the FOR are 
executed, until the computer gets to the matching NEXT statement. 
The NEXT tells your Plus.''4 to add one to the counter II the counter is 
less than or equal to the end value, the computer returns to the pro- 
gram line after the FOR statement. Otherwise, your Plus 4 continues 
with the first statement after the NEXT, 

Example using a FORNEXT loop 

10 PRINT. "COUNTUP. . ." 

20 FOR J = 1 TO 10 

30 PRINT "WE HAVE"; J 

40 NEXT J 

50 PRINT "WE COUNTED UP TO"; J 

One more thing about FOR-'NEXT. you can also specify a STEP value m 
the FOR statement. Instead of adding 1 to the counter variable, your 
Plus/4 adds your STEP value. If you use a STEP of 5 with the statement 
FORM = 10 TO 30. for example, thecounter would count 10. 15. 20. 
25. 30 after each loop The STEP command even lets you count back- 
wards (by using a negative STEP value) 



77 



1 J 



Another example, with a negative STEP 

10 PRINT "COUNTDOWN. . ." 

20 FOR J = 10 TO STEP - 1 

30 PRINT "WE ARE AT" : J 

40 NEXT J 

50 PRINT "WE HAVE LIFT-OFF AT"; J 



Statement Name: DO UNTIL/WHILE. . . LOOP UNTIL/WHILE 
Format: DO UNTIL [coridition | WHILE [condition | 
some BASIC statements 
lEXITl 
LOOP UNTIL Icondition | WHILE [condition] 

The DO. LOOP statement combination is another uvay to create a 
loop. This statement combination is very powerful and versatile. The 
DG.'LGOP method ot loops is a common technique of structured 
programming languages. In this chapter well discuss just a few 
possible uses. 

~~' If you want to create an infinite loop, just start a seciion of program 

lines with DO, and end it with a LOOP statement, like this: 

100 DO: PRINT "GOING UP" 
_^ 110 LOOP 

n 

Press the STOP key to end the program. 

A more useful form is to combine the DO/LOOP with the UNTIL 
statement. The loop will run continually unless the condition for 
■"" UNTIL happens. 

— . 100 DO: INPUT "DO YOU LIKE YOUR COMPUTER"; AS 

■' i 110 LOOP UNTIL A$ = "YES" 

120 PRINT "THANK YOU" 



For the other ways you can use the DO- LOOP, see the BASIC 
Encyclopedia at the end of this book. 



78 



CONDITIONAL 

OR 

DECISION 

MAKING 

STATEMENTS 



Conditional statements are used to make decisions. One of the most 
powerful abilities of a computer is to make decisions based on wtiat Is 
going on. One of [he conditional statements available on tfte Plus/4 is 
known as IF THEN statements. 

Statement Name: IF/THEN 

Format: IF condition THEN do tfiis (only if ttne condition is true) 
Basically, the IFTHEN statement works like this. 

IF (this statement is true) THEN {do this statement) 

Actually, you have always known how conditional statements work 

How many times have you heard this famous line^ 

IF you eat all your vegetables THEN you can have dessert That may 
seem a bit trivial, but that Is the gist of the IFTHEN statement. 

f the condition in the IF statement is true, everything after the THEN 
IS executed. 



-J 



EXAMPLE: 

10 INPUT" WHAT'S THE TENTH LETTER OF THE ALPHABET" ;A$- 

20 IF A$ = "J" THEN PRINT "RIGHT": GOTO 100 

30 INPUT "IS THIS AN A" ;X$ I 

40 IF XS = "A" THEN 60 

50 PRINT "WRONG, TRY AGAIN" : GOTO 30 | 

60 PRINT "TYPE A B" 

70 GETKEY A$:IF A$ = "B"THEN PRINT "RIGHT" L 

100 PRINT "THAT'S ENOUGH OF THIS, ANYWAY" ■ 

In line 40 , we just say THEN 60. This actually means THEN GOTO 60, _ 
but since the THEN GOTO combination is used so often, BASIC allows 
you to leave oft the GOTO, An optional step for the IF THEN statement 
IS the ELSE clause, that directs your computer to a specific action if 
the original IF condition was not met. An example showing the ELSE 
clause would be, IF B > 5 THEN 40 ELSE GOTO 10. The BASIC Ency- - 
clopedia explains the IF'THEN/ELSE statement more fully. 



7&— 



SUBROUTINES " yo'^ ^3^® something in your program that has to be repeated in more 
than one place in your program, you have two choices: you can have 
duplicate routines, or you can create a subroutine. A subroutine is a 
section of your program that can be used from anywhere else in your 
program When the subroutine is finished, the program automatically 
continues at the statement just after where the subroutine was called. 

Statement Name: GOSUB/RETURN 
Format:GOSUB line # 

The GOSUB statement is used to ca!l a subroutine. Like the GOTO 
statement- control is transferred to the line number specified in the 
statement However, unlike the GOTO, the Plus'4 remembers where 
the GOSUB is located. When a RETURN is next encountered, control 
returns to just after the GOSUB statement. 

Example 

5T=0:FORJ = 1 TO 99 

10 PRINT "GIVE ME A NUMBER FROM 1 TO 10" 

20 INPUT N 

30IFN- 1 THEN GOSUB lOOiGOTO 20 

40IFN 10 THEN GOSUB 100:GOTO 20 

50T = T4-N 

60 NEXT J 

70 PRINT "THE TOTAL IS"J 

80 END 

100 PRINT "THAT NUMBER IS OUT OF RANGE" 

105 PRINT "PLEASE TYPE A NUMBER BETWEEN 1 AND 10 

110 RETURN 

If a RETURN is encountered when there are no active GOSUBs, you 
get a RETURN WITHOUT GOSUB ERROR You should be careful that 
the computer never gets into one of your subroutines except by GOTO. 
One method is to group the GOSUB and GOTO statements together, 
protected from normal program execution by an END statement. 

Statement Name REM 

Format: REM message 

The REM statement is used to comment (or REIVIark) on your pro- 
grams. The REM statement is not executed as pari of the program, it is 

80 



a message that can be seen only when looking over the LISTing of a 
program. Often, if you don't comment, six months alter you write the 
program you might forget what some part does. You can use REM 
statements to put in reminders, so you can more easily figure out what 
you really meant, or give others information with your messages. 

Example: 

1560 E= R/I'9:REM THIS FIGURES OUT A PITCHER'S ERA 

100 INPUT A, B: REM A IS HEIGHT IN INCHES AND B IS WEIGHT 



m 
m 

81— i 



SUMMARY As we REMarked in the introduction, this would not be a complete tuto- 
nal on BASIC We just gave you some of the BASICs^ Every BASIC 
command in the Plus/4 is in the BASIC Encyclopedia, vifith format, 
description, and examples. Don't be afraid to experimenl If you are 
serious about learning BASIC, get some of the bOQl<;son BASIC pro- 
gramming listed in the Section 14 of the Encyclopedia. Programming is 
like eating salted peanuts: once you start, you may not be able to stop. 



82 



n 



CHAPHR? 



USING 
GRAPHICS 



COLOR 



• Graphics characters 

• Character animation 



• Controlling colors 



High resolution graphics 



Points, lines, and labels 



Squares, circles, polygons, and painting 
Multi-color graphics 



83 



GRAPHICS 
CHARACTERS 



Each letter key contains 2 different grapfiic ctiaracters, as do ttie @. . 
' , and Englisti Pound keys. To print graphics characters, you must hold 
down the SHIBX or JCf Keys while you press the key for the 
graphics symbol you want. 

When your Plus'4 is in upper-case/graphics mode, hold down 
[- SHIFT and press a letter key to display Ihe graphics character on 
the right side of that letter key These characters include the playing 
card suits, a solid and a hollow ball, and a set of lines and connecting 
characters that let you draw many different pictures on your screen. 
Here are some examples to help you get used to these characters: 



Exercise 


1 : Large Circle 




y 


Step! 
2 
3 
4 
5 


Press down the SHIFT LOCK- key. 
Press the letter U then the letter 1 
Press the RETURN key. 
Press the leiter J then the letter K, 
Press the RETURN key. 


m 
m 


Exercise 


'2: Snake 




-J 


Stepi: 
2 
3 
4 
5 


Press down the SHIFTLOCK key. 
Press U. then 1. then U. then 1. then U. 
Press the RkTi'UHN key 
Press K. then J. then K. then J, then K 
Press the RETURN key. 


thenl. 
then J 


m 

m 

1 1 


Exercise 3: Crooked Line 




uJ 


Step 1 
2: 
3: 


Press down the SHIFTLOCK key 

Press E. then D, then C. then ". Ihen R Ihen R 

Press the RETURN key 





Exercise 4: Two Crosses 



Slept' Press down the SHIFTLOCK key 

2: Press M. then SPACE, then N. then SPACE, then — . 

3: Press the RETURN key. 

4: Press SPACE, then V. then SPACE, then ', then +. then 

5: Press the RETURN key. 

6: Press N, then SPACE, then M, then SPACE, then — . 

7 Press the RETURN key. 



^ 



84 



When you are finished, press ^ SHIFT LOCK again so it pops up. 

Did yo u wonde r why the computer doesn't say SYNTAX ERROR when 
you hit RETURM '^ After all, you had characters on the line that 
weren't commands that the computer can understand 

The reason is that the Plus 4 doesn't pay attention to the line you typed 
if you hoio down SHIFT when you press RETURN. If you press 
RETURN without the .SHIFT i key, the computer tries to figure out 
what you fnean when you're |ust drawing pictures 

So far we haven't talked about the graphics characters on Ihe left side 
of the keys. These graphics work just like the right side characters, ex- 
cept that you hold down the , ; 0= :; key instead of .,,:SIi^T . , There is 
no ^ lock, so you must hold it down yourself. 

You can print this set of graphics in either upper-case/graphics mode 
or upper'iowef-case mode. They are always available 

The left side graphics characters include lines and angles used for draw- 
ing charts and tables. For example, here's how to underline a word 

First, move the cursor to the line below the word you want to underline. 
Then hold down the "^"f^ key and the T key. which prints an under- 
line graphic. Hold these two keys down until the word is underlined. 



Exercise 5: Half Bar 

Stepi: Hold down the O key with one hand during the whole 
exercise. 
2. Press D, then I. then I. Ihen F 
3: Press the :.., RETURN key. 



Exercise 6: Wedge 



Step 1 
2 
3 



85 



Hold down the .C= key and hit I then Y, then U 

Hold down the CONTROL key and hit 9, 

Hold down the C" key and hit I, then 0, then R then @, 

then SPACE 

Press the RETURN key. 



Exercise?: Window ^ 

Stepi: Hold down the O key until step 4. ^ 

2: Press A, then :R. then S, then RETURN. ■ 
3: Press Q. 

4; Let go of O;:: (it's OK, honest), HI 
5: Hold down SHIFT and hit +. 

6: Let go of SHIFT and hold down & again. Don t let j 

go of it any more 

7: Press W, then RETURN . r^ 

8: Press Z. then E, then X, then RETURN ,, 

The purpose of these exercises is to show you how the graphic sym- — * 
bols of the Plus/4 can be manipulated to create different shapes and 

figures. These are only a handful of the figures and representations j 

you can develop. Now that you have a good idea of what is involved in 

using the graphic symbols to build different forms, you should experi- i 
ment with them yourself, and see what you come up with. 



86 _^ 



CHARACTER Movies are really a sequence of still pictures. Each picture is a little 
ANIMATION ^'^'^fs'^' '^o'Ti the one that came before. The projector shows each 

picture for a very short time, then goes on to the next one. The scene 

becomes animated. 

Computer animation works the same way. First the computer draws 
one picture, then it changes the picture slightly. The Plus/4 is fast 
enough to allow objects to move smoothly all around the screen in 
your games and practical programs. 

You can't type fast enough to create animation. A movie is animated 
at a rate of 30 pictures per second. The changes must be fast enough 
to fool the eye, So you must use a program to draw a picture, wait for 
a split second, then change to a new picture. 

To get the program to create pictures we use the PRINT statement with 
the graphic characters. The simplest type of animation involves alter- 
nating two characters to get the effect of movement. 

This program simulates the movement of a pulsing ball. 

Type NEW and press RETURN before entenng each new program. 
Remember to press RETURN after each line in all these programs. 



10 PRINT" HOME 

20 FOR L = l TO 100 

30 NEXT L 

40 PRINT ' ' HOME 

50FORL = 1TO 100 

60 NEXT L 

70 GOTO 10 



SHIFT Q" 



SHIFT 




Type these keys 
simultaneously 



Type RUN and press return 



To get a more interesting effect you can build a small picture from 
several graphic characters, then change a few of the characters 
while leaving others in the same place. This gives the effect of part 
of an object moving, demonstrated in the following program. 



87 



IMPORTANTTO NOTE: Each lime SHIFT; or O, is 

referred to, it should be typed at the SAME TIME as the l^ey 
following it when entering the program. 



10 PRINT" HOME SHIFT M SHIFT W SHIFT N' 

20 PRINT "SPACE O + SPACE ■' 

30 PRINT" SHIFT N SPACE SHIFT M" 

40 FOR L - 1 TO 100: NEXT L 

50 PRINT" HOME SPACE SHIFT W SPACE" 

60 PRINT " & T C + C' T" 

70 PRINT "SPACE C' G C« G" 

80 FOR L - 1 TO 100 : NEXT L 

90 GOTO 10 



Type RUN and press return 



In both examples of animation so far, we've worked on only one area on 
the screen. The next step is to move the animated iigure around. The 
TAB function helps when you want to move objects from the left edge. 
The following program portrays a snake crawling on the screen. 



Remember that 
together. 

5 FOR A = TO 30 
10 PRINT" SHIFT 
20 PRINT TAB {Al- 
so PRINT TAB (A) " 
40FORL=lTO100 
50 PRINT" SHIFT 
60 PRINT TAB (A+1) 

SHIFT U" 
70 PRINT TAB (A -1) 

SHIFT K ' 
80 FOR L- 1 TO 100: NEXT L 
90 NEXT A 



SHIFT and the following l<.ey are still typed 



CLR 
SHIFT 
SHIFT 

NEXTL 
CLR ■ 
SHIFT 



u 



u 


SHIFT 


I 


SHIFT 


U 


SHIFT 


I 


K 


SHIFT 


J 


SHIFT 


K 


SHIFT 


J 



I SHIFT U SHIFT I 



SHIFT J SHIFT K SHIFT , J 



Using characters like the ball ( SHIFT Q), you can play video 
games on the screen. To move a ball, just erase the ball and replace i 
at a new position, as in this program. 



88 



10 PRINT " SHIFT CLR 

20 PRINT "SPACE SHIFT Q [| 

30 FOR L- 1 TO 50: NEXT L 
40 GOTO 20 



Left cursor arrow 
leave a space here 



Type RUN and press the RETURN 
you want to stop moving Ihe ball. 



key. Press the STOP key when 



89 



-J 



CONTROUJNG 
COLORS 



Separate colors can be put into each part of the screen. The border 
can be one color, the background a different one, and each character 
can have its own color. You already know how to set the character col- 
ors using the keyboard. The COLOR command adjusts the color of the 
other screen areas. 

Turn the border of your screen red by typing the command COLOR 4.3 and 
pressing the RETURN key. The number 4 in the command stands for 
the border area, and color number 3 is red (the same number as on the 
key marked RED). 

Now type COLOR 0, 7 and hit RETURN . The screen background 
turns blue. The number stands for the background, while the 7 is blue 
(also the same as the keyboard). 

The first number after the word COLOR stands for the area on the 
screen you want to change. Area is the background, 1 Is the char- 
acter color, 4 is the border. You'll learn about areas 2 and 3 when you 
get into multi-color graphics later in this chapter. 

Screen Area Numbers 

AREA # AREA NAME 




1 
2 
3 
4 



Background 
Character 
Multi-color 1 
rvlulti-color2 
Border 



_J 



_J 



u 
u 

m 

y 



Each color also has an adjustable brightness level, calied the lumi- 
nance. You can add a number from (darkest) through 7 (brightest) 
after the color number to vary the color. Type COLOR 4 ,3. and hit 
RETURN. The border becomes a dark red. Type COLOR 4, 3, 7 
and the border changes to a bright red. 



90 



n 



n 





Color Numbe 


rs 






COLOR# 


COLOR 


COLOR# 


COLOR 


1 


BLACK 


9 


ORANGE 


2 


WHITE 


10 


BROWN 


3 


RED 


11 


YELLOW GREEN 


4 


CYAN 


12 


PINK 


5 


PURPLE 


13 


BLUE GREEN 


6 


GREEN 


14 


LIGHT BLUE 


7 


BLUE 


15 


DARK BLUE 


8 


YELLOW 


16 


LIGHT GREEN 



In short, the COLOR command looks like this: 

COLOR area, color, luminance 

Here is a quick program to show you all the Plus/4's colors: 

First type NEW and hit RETURN . Don't forget to hit RETURN 
after each program line. 

10 COLOR 0, 7, 7 

20FORM = 0TO7 

30FORN = lTO2 

40FORL = lTO16 

50 PRINT ■ ■ CONTffOC" ""fflrS^Sn' ' ; 

60 READ A 

70 COLOR 1, A, M 

80 PRINT" "; 

90 NEXT L 

100 PRINT 
~^ 110 RESTORE 

120 NEXT N,M 
-^ 130COLOR1, 2, 4 

200 DATA 7,14,4,13,6,16,11,8,10,9,3,12,5,15,2,1 

pj Now type RUN and hit RETORN ■, to see a bright blue screen with 

each of the other 15 colors shown at each luminance level. 

" NOTE: Like most of the BASIC graphic terms reviewed in this 

chapter, COLOR may be referred to as a statement or com- 
— • mand interchangeably. The distinction is unimportant in ex- 

plaining COLOR, or any other graphic commands, since it is 
__ based on whether the term is more often used in direct or pro- 

• 1 gramming mode. 

91 



HIGH 

RESOLUTION 

GRAPHICS 



Your Plus'4 screen contains 25 rows of 40 characters each, or 1000 
total chiaracter positions on the screen. Each character is iormed out of 
single dots, with 8 rows of 8 dots each making an entire character. Your 
screen has a total of 320 dots on eacfi row, and 200 rows of dots, or 
64,000 dots all together. Your Plus/4 has control over every single dot. 

Using normal graphics, you have limited control over the individual 
dots. You must use the 256 characters in each character set built into 
the Plus,'4. which lets you create many pictures. But think of how many 
you could create if you could control each dot by itself! 

The high resolution graphics ability of the Plus/4 lets you do just that. 
You can use commands that let you draw and erase dots, lines, circles, 
and other shapes 

There Is one limit to high-res graphics The Plus/4 can only use two 
colors in each 8x8 character position. That is, each 8x8 space on 
the screen where characters usually go is limited to two colors (fore- 
ground and background color for that square). You can use different 
colors for each different character position, but only two colors within 
that position. Another graphic mode that will be covered later in this 
section, multi-color mode, allows up to four different colors per 
character position at the cost of the resolution available in the high- 
resolution mode 

This program utilizes some of the high resolution graphics capability of 
the Plus/4, in particular the GRAPHIC command. Start by typing NEW 
and hitting RETURN Hit the RETURN key after typing each 
line. After typing in the entire program, type RUN and hit RETURN 
as usual 

10 COLOR 0.1 

20 GRAPHIC 1,1 

30 FOR L = 2 TO 16 

40 COLOR 1,L,2 

50 DRAW 1,0,L-12 TO 319,L' 12 

60 DRAW l.L- 18,0 TO L ■ 18,199 

70 NEXT L 

80 FOR L= 1 TO 5000:NEXT 

90 COLOR 1.2,3 

100 GRAPHIC 

Notice thai the colors change near the intersections. 



_J 



92 



To switch Irom normal graphics (also called Text Mode) lo high-res, 
just type the command GRAPHIC 2,1 and hit . HETXJRN . What hap- 
pens';' The screen goes Plants and the cursor reappears near the bot- 
tom of the screen The Plus/4 divided up the screen inio 2 separate 
sections the top for graphics and the bottom live lines for text. If you 
don't want the bottom five lines for text, you can use the command 
GRAPHIC 1,1, but you won't be able to see any commands you type. 

You can switch back and forth from graphics to text using the 
GRAPHIC command- The command GRAPHIC switches the screen 
back to text, while GRAPHIC 2 switches back to high-res without eras- 
ing the screen. Adding .1 after the command erases the screen. 

In general the GRAPHIC command looks like this: 



GRAPHIC mode, dear ■ 



this part IS optional 



Mode 
Number 



Effect 



Text 

High-res 
High-res -i- text 
Multi-color 
Multi-color -I- text 



Clear 

Number 



Effe ct 

Don't clear screen 
Clear screen 



There is another way to clear the high-resolution screen. The command 
SCNCLR erases the screen without changing the graphic mode. 

Once you use high-resolution graphics, the computer sets aside 10K of 
memory for your hi-res screen. This memory is taken from the BASIC 
program area. When you are through using graphics, you can reclaim 
this memory by using the command GRAPHIC CLR. 



93 



POINTS, Type the commands GRAPHIC 2.1: DRAW 1,0,0 and hit retorn 

LINES Look closely at the upper left corner of the screen. The Plus/4 drew a 



AND 



black dot there. 



LABELS In the DRAW command, the first number is either 1 (foreground color) 
or (background). The next two numbers are for the row and column 
positions for the dot. So if you wanted to draw a dot at column 17, row 
20, just type DRAW 1,17,20. To erase the same dot type DRAW 0,1 7,20. 

The DRAW command can also draw a line between any two points. 
Just add the word TO and the coordinates of the other end, like this: 
DRAW 1,1,1 TO 100,100. This draws a line from 1,1 to 100,100- 

If you are used to drawing graphs in math, you might gel a little con- 
fused at first while using the computer The coordinate system in the 
Plus/4 is different from what you're used to. In math the 0,0 point would 
either be at the center or the lower left corner of the screen, but on the 
computer it is the upper left corner. You'll get used to the system in the 
computer as you practice. 

Once you have put a point or line on the screen, you can draw a line 
from it to any other point like this: DRAW 1 TO 150,50, This draws a line 
from the last point drawn to column 150, row 50, If your program uses a 
lot of DRAW TO commands, you could place the first dot at a position 
on the sc.een by using the LOCATE command, as in LOCATE 100,100. 

The DRAW command can have several forms, such as: 



COfVlMAND RESULT 



DRAW color source, column, row POINT , J 

DRA'W color source, column, row TO column, row LINE 
DRAW color source TO column, row LINE DRAWN 



FROM LAST POINT 



^ 



Color source is for the background, 1 for the foreground 

To erase points or lines on the screen, use the DRAW command fol- 
lowed by the number 0. If you created a point with DRAW 1,1,1, you can 
erase it with DRAW 0,1,1. A line created with DRAW 1,1,1 TO 100,100 is — ^ 
erased by DRAW 0,1,1 TO 100,100. 



94 J 



This program draws a curve based on the sine function. Type NEW 
and hit retubk . Remember to hit the RETURN l<;ey after each 
line, then type RUN. 

10 COLOR 0,1 

20 COLOR 1,2 

30 GRAPHIC 1,1 

40 LOCATE 0,100 

50 FOR X = l TO 319 

60 Y = INT (100 + 99 •SIN(X/20)) 

70 DRAW 1 TO X,Y 

80 NEXT X 

90 FOR L=l TO 5000 

100 NEXT L 

110 GRAPHIC 




Don't type NEW after RUNning the last program. To plot the program 
differently, change line 70 to: 

70 DRAW 1, X, Y 

This program plots the same curve using points instead of lines. 

The Graphs are more easily understood and useful if you label them. You 
Char '^^'^ '^^^ '*^^ CHAR command to mix text right into a high resolution 



Command 



drawing. For instance, the statement CHAR 1,0, 5, "HELLO" puts the 
word HELLO into the sixth row at the left edge of the screen. The first 
number after the word CHAR is either 1 (for draw) or (for erase). The 
next two numbers are the column and row where the text appears. 

Leave the last two programs in the computer: don't type NEW. Add 
these lines: 

95 



81 CHAR 1,0,0,"GRAPHOF":CHAR 1,0,1, "FORMULA" 

82 CHAR 1,0,2,"Y = SIN{X)" 

83 DRAW 1,0,100 TO 319,100,189,0 TO 189.199 

84 CHAR 1,0,12, "X-AXIS": CHAR 1,22,0,*'Y" 

85 CHAR 1,22, 2, "A"; CHAR 1,22, 3,"X" 

86 CHAR 1,22,4. "I": CHAR 1,22,5,"S" 




m 
m 
m 

m 
m 



96 



, J 



, J 



SQUARES, 

CIRCLES, 

POLYGONS, 

AND 

PAINTING 

Drawing 
Rectangles 



Using the DRAW command, you can draw pictures by plotting many 
dots or lines. To draw a square, you can use the command DRAW 1,0,0 
TO 100,0 TO 100,100 TO 0.100 TO 0,0 (plotting each endpoint of the 
square) or you can just use the BOX command. 

THE BOX COMMAND 

Your Pius 4 includes a command to make it easier to draw squares and 
other rectangular shapes. The BOX command lets you pick the points 
of 2 opposite corners of the square. To duplicate the same box as in 
the above example, just use BOX 1 ,0,0,100,100. The number 1 again 
means that you want to draw and not erase. The next four numbers are 
the coordinates of the box's opposite corners, (0,0) at the upper-left 
corner and (100.100) near the middle of the screen. 

The BOX command can form any rectangle just by changing the cor- 
ners. You can even rotate the box by specifying an angle (in degrees) 
after the last coordinate, like this: BOX 1,50,50,100,100,45. The box is 
rotated 45 degrees clockwise, 

If you would like to draw a solid box instead of just the outline, you just 
add a comma 1 alter the angle. A solid box at the center of the screen is 
shown as BOX 1,100,50,220,150,, 1. Notice that you need a comma to 
take the place for the angle, even though you don't want the box rotated. 

Some typical forms of the BOX command are: 



COI^MAND 

BOX on, columni , rowl , column2, row2 
BOX on, coll , rowl , col2, row2, angle 
BOX on, coll , rowl , col2. row2, , fill 
BOX off, coll , rowl , col2, row2, angle, fil 



EFFECT 



Outline 
Rotated 
Solid box 
Erase area 
of screen 



Here are a couple of programs that use the BOX command: 

Don't forget to type NEW then hit RETORN before entering each 
program, and press .RETURN after typing in each line. 



10 COLOR 0.1 
20 COLOR 1,2 
30 GRAPHIC 2,1 
40A=RND(1)*20- 



10 



97 



continued on next page 



50 FOR L = TO 359 STEP A 
60 BOX 1, 100, 30, 220, 130. L 
70 NEXT L 

80 FOR L= 1 TO 2000: NEXT L 
90 GRAPHIC 0,1 

5 TRAP 60 
10 GRAPHIC 2.1 

20DEFFNA(X)^ INT(RND(1)- X) 
30 COLOR 1,FNA(15) + 1 

40 BOX 1, FNA(320), FNA(160), FNA{320). FNA(160).. 1 
50 GOTO 30 
60 COLOR 1,2,3: GRAPHIC 

Hii RETURN and type RUN after each program is completely en- 
tered Hold down the STOP key to end the program 

The second program draws different colored squares all over the 
screen You II notice some parts of the screen changing when other 
parts near them change. The reason for this was discussed earlier in 
this chapter. 

DrBWinp Your Plus 4 also has commands for drawing circles. Like the BOX 
CirClBS command, we can vary the shape of Ihe circle to form an oval (also 
called an ellipse), and we can rotate the oval. We can also |ust draw 
a section of the shape (called an arc) 

This command draws a circle in the center of the screen: CIRCLE 
1.160,100.50. This tells Ihe Plus/4 lo draw a circle with its center at row 
160 and column 100, with a radius of 50. This actually produces an 
oval, since the dots on the screen are taller than they are wide. To 
change this to a real circle you must add a separate number to tell that 
the height is different from the width, like this CIRCLE 1.160.100.50.42 

The Plus/4 can also draw a square, triangle or other polygon using the 
CIRCLE command. Just tell the computer how many degrees to go 
between points on Ihe circle, like this CIRCLE 1.160.100,50.42. ...120 
This command draws a triangle, since each side is 120 degrees 
(Omitting number values while including commas in a graphic com- 
mand causes the computer to read standard default values for the 
missing number.) A simple formula lo get the angle for a polygon with 
N sides is 360/N. 

Here s a quick program for drawing polygons: 

98 



n 



- J 



10 GRAPHIC 2,1 

20 INPUT"HOW MANY SIDES"; A 

30 IF A<2 OR A--100 THEN PRINT "DON'T BE RIDICULOUS" 

GOTO 20 

40 CIRCLE 1,160,80,40,33,,, ,360/A 

50 GOTO 20 

You can choose to draw only an arc instead of a whole circle. 
The CIRCLE command accepts the starting and ending angles 
in degrees, right after the height number. The command CIRCLE 
1,160,100,50,42,90,180 displays only the lower right section of 
the circle. 

To rotate an oval, add Ihe angle of clockwise rotation after the 
command, like this example CIRCLE 1,160. 100, 100, 20., ,30. 

The usual forms of the CIRCLE command are: 



COfvlfvlAND 


EFFECT 


CIRCLE on, center column, center row, radius 


oval 


CIRCLE on, c-col, c-row, width, height 


circle/oval 


CIRCLE on, c-col, c-row, wid, ht, start, finish 


arc 


CIRCLE on, c-col, c-row, width, height,, .angle 


rotate oval 


CIRCLE on, c-col, c-row. wid. ht,,,,pornt angle 


polygon 



, J NOTE: When there are commas without numbers in a command 

such as CIRCLE or BOX, the Plus,/4 automalically interprets the 

— • comma as an input of the default value for that parameter of the 

command. For example, CIRCLE,160, 40, 100,100 is read by the 

, computer as CIRCLE 1 , 160 ., . reading the default value of 1 for 

the coior source, 

'_' This next program uses the CIRCLE command for an interesting effect, 

^ Type NEW then hit RE'Ttn^ to erase the las! program from memory 

before typing in this program 



\ \ 



99 



10 COLOR 0,1 _ 

20 COLOR 1,2 

30 GRAPHIC 1,1 

40A = RND(1)*20+ 10 — 

50 FOR L = TO 359 STEP A 

60 CIRCLE 1, 160, 100, 80, 40„,L _^ 

70 NEXT L 

80 FOR L = l TO 2000: NEXT L _^ 

90 GRAPHIC 0,1 

Here's a program you can try that uses ttie CIRCLE command to create '"^ 
a simple design. 

NEW 

10 COLOR 0,1 ^_ 

20 COLOR 1.2 

30 GRAPHIC 2,1 ^' 

40FORL = lTO4 ~ 

50Y = 50 

60irL = 2ORL = 4THENY=100 ^- 

70 X= L*35 + 50 

80 CIRCLE 1, X, Y, 50, 42 M 

90 NEXT L 

100 PRINT "PLUS /4 CIRCLES" 




"d 



100 



Command 



The The PAINT command fills in any enclosed area up to the boundaries 
Paint formed by any lines drawn on the screen. If there are no drawn tines, 
the screen is filled right to the edge. The BOX command can be used 
to fill in boxes and rectangles with color. The PAINT command can 
color in irregular shapes and other non-uniform areas on the screen 
that can't be filled with other commands. 

In (he last exercise, we created a 4-ring symbol, By adding some 
PAINT commands to the program we can color in only the areas 
between the rings. 

Add these lines to the last program: 

110FORL=0TO 1 

120 PAINT 1,120 + 35 *L, 75 

130 NEXT L 



101 



MULTI- '^^^ Plus/4 high resolution graphics give you control over every single ■—J 

COLOR '^^' °' "Pi'^fil on the screen, but you have seen that the abilily to put 

rRflPHIPI colors close together is limited. Most high-res programs can use only ^ 

uruirnibo Q^g ^^ ^^^ colors. 

For including more different colors, your Plus/4 has a special "in- _J 

between" graphics mode called muiti-color graphics. In multi-color 
graphics, you control half as many dots on each row as in high-res be- , 
cause each dot is twice as wide. You get 160 dots on each row. while 
still getting 200 rows. There isatrade-off for the use of multiple colors, 
which is slightly lower resolution. 



.J 



To begin using multi-color graphics, review the GRAPHIC command 
earlier in this chapter You'll see that the multi-color screen wilhoul 
text IS GRAPHIC 3 and the multi-color screen with 5 lines of text is 
GRAPHIC 4 

Now look al the table listing the COLOR command. There are two 
areas that we haven't used yet. areas 2 and 3. These areas hold two 
extra colors. You can use any of the ihree colors (1. the text color: 2. an 
extra color; and 3, another extra color) These colors do not interfere 
with each other on the screen the way the high-res colors do in some 
previous programs in this chapter 

These two programs make use of multi-color graphics, the first with the 
rings and the second showing a "neon sign" effect. 



.J 



.J 



10 COLOR 0.1 
20 GRAPHIC 4,1 

30FORL = lTO4 

40Q = L: IFQ >3THENQ=Q-3 

50 COLOR Q.L^l 

60Y -50 

70 IF L - 2 OR L = 4 THEN Y= 100 

BOX- LM8 - 25 

90 CIRCLE Q,X,Y, 25.42 

100 NEXT L 



102 



J 



. i 



. i 



. 4 



Type NEW then hit RETURN Don't forget to hit tine RETURN key 
after eachi line. Type RUN and iiit RETURN atllieciid 

10 COLOR 0,1 

20 GRAPHIC 3,1 

30 COLOR 3,1 

40 TRAP 200 

50 DRAW 3,10,10 TO 10.100: DRAW 3.10.55 TO 30,55 

60 DRAW 3,30,10 TO 30,100: DRAW 3,50,10 TO 80,10 

70 DRAW 3,65,10 TO 65,100: DRAW 3,50,100 TO 80,100 

80FORL = 0TO7 

90COLOR3,2,L 

lOO FOR M= 1 TO 100: NEXT M 

110 NEXT L 

120 COLOR 3,1 

130 FOR M - 1 TO 100: NEXT M 

140 GOTO 80 

200 GRAPHIC 0: COLOR 1,2,7 

Color area 3, Ihie second of the multicolor areas, has a special ability 
that none of the otfiers has. Once you have drawn on the screen using 
area 3, you can change that color everywhere it appears on the screen 
by using the COLOR command. If you set the color with COLOR 3.5 
and draw using that color, your graphics appear in purple. If you then 
change the color with COLOR 3.6, all the purple areas would change 
to green. This doesn I work with any other area 

The Plus/4 Programmers Reference Guide contains more information 
about graphics. 



103 



y 



u 



m 
i 



i 
i 



n 



n 



CHAPTERS 



. i 



MAKING 

SOUND 

AND 

MUSIC 

ON 

THE 

PLUS/4 

• Introduction 

• Volume command 



• Sound command 



• Creating sound effects 

• Making some music 



The Plus/4 Music Machine 



104 



INTRODUCTION 



Here is a short program to make music on your Pius/4. Type in the pro- , 

gramexactly as it appears, and remember to press • RETURN at the 
end of each line. When the program is typed in, type RUN and then 

press RETURN . When the program asks you to enter a number, ~^ 
type any number from to 1023 and press v,RETURN.i, . To stop the 

program, enter a zero as your value, UJ 



THE 

VOLUME 

COMMAND 



10 VOL 8 

20 DO 

30 INPUT X 

35IFX ■ 1023 OR X- 

40 SOUND 1, X, 10 

50 LOOP UNTIL X = 



THEN PRINT ■'0 TO 1023, PLEASE": GOTO 30 



Press the RUN/STOP key to Stop the program. 

Here s hov; lo play a single note on your Plus/4. Type NEW and press 
l:_^TURN,., to clear the Plus,. 4s memory. 

First: Type NEW and press RETURN 
Type VOL 8 and press RETURN 

Second: Type SOUND 1,266,60 and press -JtEtfllttM 

You should hear a note play for about a second and then stop If you 
don't hear anything, turn up the volume of your television or monitor 
and try it again. 

These two steps are the only commands that you need to know to play 
music on your Plus/4. Let's look at what these two commands do 

The VOL command controls the VOLume of the notes that the Plus/4 
plays. Think of the first three letters of the word "volume" to remember 
the VOL command. The number that comes after VOL is the setting 
for the volume. Think of the VOL command as a volume knob on the 
Plus 4 When the knob points to zero, the volume is off and you won i 
hear anything. When the knob is set at 8. the volume is turned up all 
the way. and your Plus'4 plays as loud as it can. 

Try the first example again and use a different number after the VOL 
command. The smaller the number, the softer the note is played. 



m 

i 

-J 



105 -- 



n 



THE 

SOUND 

COMMAND 



r ^ 



f 1 



The SOUND command tells your Plus/4 everything il needs to !<now 
about the sound you want to play The SOUND command is followed 
by t^^ree numbers that describe the note: 

SOUND voice, note value, duration 

Tlie first number in the sound command refers lo voice. The number for 
voice can be a 1 ,2 or 3, The Plus/4 sound is produced by two different 
"voices' , 1 for the first voice and 2 for the second voice,. The third voice 
option applies to voice 2's ability to produce either a tone or noise. 

Voice 1 —This voice plays only tones. Select this voice with a 1 after the 
SOUND command. 

Voice 2 — This voice is like voice 1 . but can be used to play tones or 
noise for sounds. Type a 2 in the command to use this voice for tones, 
or a 3 to use this voice for noise, to make sound effects like thunder 
and rain. 

The second number after the word SOUND is the note value (fre- 
quency). This can be any number from to 1023. It tells your Plus/4 
how low- or high-pitched a note to play As the numbers get larger, the 
notes get higher. The highest values (in the 1023 neighborhood} are 
not audible to the human ear 



r i 



; i 



Note. Notse is "white" only in the range of 600-940 with Voice 3. 
You can use register values outside this range to create interest- 
ing sound effects. 

Here is a chart that shows all of the notes in one scale, along with the 
note value to use. There is a complete chart of notes for the Plus/4 in 
Section 1 1 of the Plus.'4 Encyclopedia 



SOUND 

NOTE 

FREQUENCV 




i30 .59.' 5 

349 6 J 



ist • 699 880 1 

=53 'B! 7 



106 





Try the following pre 
NEW 


gram on 


your 


Plus/' 


1: 




U 




sets VOLume 






10 VOL 7 










20X = 






30 DO 


plays note 






40 SOUND 1,X,5 


= 1020 






50 X = X + 5 

60 LOOP UNTIL X 

70 VOL 






turns off VOLume 










80 END 









Type RUN and press RETURN Tfiis program allows your Plus'4 
to sfiow off some of its musical range 

Thietfiird number after the word SOUND controls the duration (length) 
of the note. This tells the Pius/4 how long to play the note. This number 
can be anything from to 65535, This number sets a timer, which 
counts time in sixtieths of a second. A duration of 60 keeps the note on 
for one second. A rule of thumb for duration is the larger the number, 
the longer the note stays on. In fact, if you use 65535. the note stays on 
for over 16 minutes. To turn a sound off. use a zero duration, which 
does not allow the sound to be produced. 



,J 



-J 



u 



107 



A 

MUSICAL 

SOUND 

EFFECT 



Sound effects can be created using either musical tones or noise. 
Combining simple BASIC programs and sound commands can gener- 
ate unusual and ente'^taining effects. For instance, [he FOR . , NEXT. . , 
STEP loop can be used creatively in sound effects, Tfiis program uses 
a FOR . . NEXT loop witfi a negative step, lo count down from a fiigfi 
number to a lower one. 



10 VOL 8 -^ 

20 FOR S - 1000 TO 700 STEP 
30 SOUND l.S, 1 
40 NEXT S 



25 



sets VOLumeat 8 



creates loop, witfi 
downward STEPs 



Type RUN and press "^SSPB^fT" to fiear ttie sound effect. The key is 
line 20. which selects a number range from 1000 to 700 going down 
the scale, STEPping down 25 numbers at a time. Finally, line 30 in- 
structs your Plus. 4 to play each note for just an instant by setting the 
DURATION to 1, which is 1/60 of a second. Experimenting with dif- 
ferent number and duration values can give you some very interest- 
ing effects. 



n 



108 



CREATING Using a value of 3 when selecting a voice in the SOUND command 
A NOISE specifies noise. This is used to create sound effects with noise rather 
cn|iun than tone. The following program uses voice 3 to create the sounds of 

EFFECT 



a windstorm. 



10 VOL 2 

20R = INT(RND(0)"10)-1 

30FORX = 1 TOR 

40 SOUND 3, 600 + 30-X, 10 

50 NEXT X 

60FORX = RTOl STEP -1 

70 SOUND, 3.600*30'X, 10 

80 NEXT X 

90 T = INT{RND(0) ' 100)-30 

100SOUND3, 600, T 

no GOTO 20 




sets VOLume level 



selects RaNDom 
number from 1 to 10 



u 



Lines 30 and 60 set up loops for the note value (frequency) of the 
sound, one increasing and one decreasing, based on the random 
number from line 20. It is important to have variation in pitch, since ^-t 

windstorms have different forces of gusts of wind. Lines 40 and 70 are 
the SOUND commands that create the noise. Lines 90 and 100 set up _^ 
a random delay to recreate the uneven nature of a windstorm with time 
lapses between howls. The program selects a RaNDom number that 
IS used for the duration of another SOUND command. This SOUND — ' 

command stays at the same pitch and provides a consistent back- 
ground noise that serves as a counterpoint to the gusts of wind, ^ 

Creating sound effects using noise is extremely challenging, trying 

to capture the right elements of the sound you want exactly To create -^ 

good sound effects, you have to be willing to experiment. 



,^ 



109 



. ^ 



. i 



MAKING ^°* '^^' we've looked at some ways to create sound effects on your 
SOME '^'^s'^' '^'^ make some music. Here are a couple of programs to try: 

MUSIC The first program turns tfie keys from 1 tfirough 8 into a piano. Type in 
tfie program and ttien type RUN 



5SCNCLR -^ 

10 FOR X= 1 TO 8: READ N(X) :: NEXT X 
20 VOL 7 
30 DO 



clears tfie screen 



THEN 40 
49ORA>56THEN90 



40GETA$:IFA$ = " 

50 A = ASC(AS): IF A 

60N = A-48 

70SOUND1,N{N), 5 

80 COLOR 0, N, 3 

90 LOOP UNTIL A= 32 

100 VOL 0; COLOR 4. 2, 7 

110 DATA 169, 262, 345, 383, 453, 516, 571 



596 



Press numbers 1 ttirough 8 to play notes. The screen border even 
changes colors with the different notes When you finish playing, press 
the space bar to stop the program. 

Here are the numbers to press for a familiar song 

Twinkle, Twinkle Little Star 



1 


1 


5 


5 


6 


6 


c 












4 


4 


3 


3 2 


2 


1 










5 


5 


4 


4 3 


3 


2 










5 


5 


4 


4 3 


3 


2 










1 


1 


5 


5 6 


6 


5 










4 


4 


3 


3 2 


2 


1 












^ 








_• 


• 1 


m- -i 


»■ 


• 




• 






















y\ 






m 


m 




1 


















1 




7 








1 

























; i 



110 



This program plays a song by reading a list of DATA statements. The 
DATA statements are In pairs. The first number is the note value for the 
SOUND command and the second number Is the duration for ihe 
SOUND command. 

Row Boat 

10 VOL 8 
20 DO 

30READX. Y 
40SOUND1, X, Y 

45FORD=l TO550:NEXT -* 

50 LOOP UNTIL X = 
60 END 

100 DATA 169, 45, 169, 45, 169, 30 
110 DATA 262, 15, 345, 45. 345, 30 
120 DATA 262, 15, 345, 30, 383, 15 
130 DATA 453, 60, 596, 45, 453, 45 
140 DATA 345, 45, 169, 45, 453, 30 
150 DATA 383, 15, 345, 30, 262, 15 
160 DATA 169, 60 
200 DATA 0, 



This loop creates 
a briei delay 
between notes 



This program plays notes going up and down scales at different 
speeds, and displays some color bars along with Ihem. 



~-J 



10 VOL 8 

20 DO 

30D = INT{RND(0) -5)- 2: REM DURATION 
40 S = INT (RND{0) '300)- 700 : REM START 
50R = INT(RND(0) "(1020-5)): REM RANGE 
60P = INT(RNDtO)'30)- 5: REM STEP 
70T = SGN{RND(1) - ,5): IFT = 0THEN70 
80 FOR Z = S TO S - T*R STEPP'T 
90 SOUND 1,Z,D 

100Y = {ZAND15) + 1:F0RX=^1T0D 
110 PRINT CHR$(18) -COLOR 1, Y: PRINT" 
120 NEXT X.Z i 

130 LOOP 



these REMark state- 
ments help you keep 
track of which line 
does what 



leave a space here 



. 4 



THE 

GREAT 

PLUS/4 

MUSIC 

MACHINE 



The last program is a little longer. This is the "GREAT PLUS/4 MUSIC 
MACHINE". When you press a key from 1 through 9, the note is played, 
and a note appears on the staff on the correct line. 



5 GOSUB 1000 

6F0RX = 1T0 9: READN(X): NEXT X 

a CHAR 1,8. 1,""THE GREAT MUSIC MACHINE" 

10 VOL 7 

20 DO 

30 GET AS: IF AS = •"■ THEN 30 

35 A = ASC(A$): IF A<49 OR A -57 THEN 50 

36 N= A -48 
40 SOUND 1, N(N), 4 
45GSHAPEN$, 150, 8 " (6 + (9-N)),4 
46 FOR Z- 1 TO 50: NEXT Z 
47GSHAPEN$, 150,8 -(6 + (9 N}), 4 
50 LOOP UNTIL A = 32 



no space 



55 VOL 0: GRAPHIC 0: SCNCLR 

60 END 

100 DATA 345, 383, 453, 516, 571, 596, 643, 685, 704 

1000 GRAPHIC 1,1 

1010 FOR Y- 60 TO 124 STEP 16 

1020 DRAW 1. 100, Y TO 200, Y 

1030 NEXT Y 

1040 AS = ■ FEDCBAGFE" 

1050FORX=lTO9: C = 13 

1060 IF INT(X.2) = X,2 THEN C= 14 

1070 CHAR 1, C. X~6, MID$ (A$. X, 1), 

1075CHAR1,C-10. X-6. RIGHT$(STRS(10 X), 1) 

1080 NEXT X 

1090 FOR X=l TO 8: FORY=ll TO 16: DRAW 1, X, Y: NEXT Y, X 

1100Y = 1: X = 8: DRAW 1, 8, 16 TO X, Y 

lllOSSHAPENS, 1, 1, 8, 16 

1120GSHAPENS, 1, 1,4 

1130 RETURN 

As you can see. its not hard to write your own sound programs. The 
ones in this chapter just give a taste of the music capabilities o; your 
Plus,'4 Dont be afraid to try new sounds and noises and create your 
own masterpiece 



112 



PLUS/4 
ENCYCLOPEDlit 



^ 

^ 



113— 




The Plus/4 Encyclopedia contains information useful for both the com- 
puter novice and expert. Some sections are musts for beginners, lil<e 
the BASIC 3,5 Encyclopedia, which lists and explains all the BASIC 
commands, statements and terminology. Other sections will be use- 
ful for those computerists whose knowledge extends beyond BASIC. 
TEDMON, the Plus/4's machine language monitor, provides some di- 
rection for machine language programming on the Plus/4. Other sec- 
tions can be helpful for all Plus/4 owners . . . listings of error messages, 
programs to try out, the musical note table, and more. The Plusi4 En- 
cyclopedia has something for all Plus/4 programmers, whether you're 
just beginning to experiment or you re a high-level programmer. 



114 



BASIC 

3.5 

ENCYCLOPEDIA 




This manual has given you an introduction to the BASIC language, to --- 
give you a feel for computer programming and some of the vocabulary 
involved. This encyclopedia gives a complete list of the rules {SYNTAX__^ 
of the BASIC 3.5 language, along with a concise description of each. 
Experiment with these commands, and remember that you can't dam- 
age your Plus/4 by typing in programs, and that the best way to learn — ' 
computing is by doing. 

The encyclopedia provides formats and brief explanations and 
examples of the BASIC 3.5 commands and statements. It is not in- 
tended to teach BASIC. If you are interested in learning BASIC, — ' 
Section 14 lists tutorial books that will help. 

Commands and statements are listed in separate sections. Within the — ' 
sections, the commands and statements are listed m alphabetical 

order. Commands are used mainly in direct mode, while statements , j 

are most often used in programs. In most cases, commands can be 
used as statements in a program if you prefix them with a line number. 
You are able to use many statements as commands by issuing them in' ' 
direct mode (i.e., without line numbers). 

The different types of operations in BASIC are listed in sections based 
on the following criteria: 

• COMMANDS; the commands used tow/orkwith programs, edit, 
store, and erase them, 

• STATEMENTS: the BASIC program statements used in numbered 
lines of programs. 

• FUNCTIONS; the string, numeric, and print functions, 

• VARIABLES AND OPERATORS; the different types of variables, 
legal variable names, and arithmetic and logical operators. 

A fuller explanation of BASIC 3,5 commands is provided in the Plus/4 
Programmer's Reference Guide, available from your Commodore 
dealer or your local bookstore. 



-J 



b 



a 



115- 



COMMAND 

AND 

STATEMENT 

FORMAT 



n 



The commands and statements presented in this section of the ency- 
clopedia are governed by consisten! format conventions designed to 
make them as clear as possible. In most cases, there are several ac- 
lual examples to illustrate what the actual command looks like. The 
lollowing example shows some of the format conventions that are 
used in the BASIC commands and statements 



EXAtVIPLE LOAD"programname".D0.'U8 additional arguments 



keywords 



JL 



argument 



I possibly optional I 



The parts of the command or statement that you nusl type in exactly as 
they appear are highlighted in boldface type in the format listing, while 
the name of the command is in capital letters. The words that you don't 
type in exactly, such as the name of a program, are printed in italics. 
When quote marks (" ") appear {usually around a program or file 
name), you should include them in the appropriate place according 
to the format example. 

• KEYWORDS, also called RESERVED WORDS, appear in upper- 
case letters and boldface type. YOU MUST ENTER THESE 
KEYWORDS EXACTLY AS THEY APPEAR. However, many key- 
words have abbreviations that you can also use (see Section 2). 

Keywords are words that are part of the BASIC language that your 
computer knows. Keywords are the central part of a command or 
statement. They tell the computer what kind of action you want it to 
take. These words cannot be used as variable names. 

• ARGUMENTS (also called parameters) appear in lower-case italics. 
Arguments are the parts of a command or statement that you select; 
Ihey complement keywords by providing specific information about 
the command or statement. For example, a keyword tells the com- 
puter to load a program, while an argument tells the computer which 
specific program to load and a second argument specifies which 
drive the disk containing the program is in. Arguments include 
filenames, variables, line numbers, etc, 

• SQUARE BRACKETS ,[] show OPTIONAL arguments. You 
select any or none of the arguments listed, depending on 
your requirements. 

• ANGLE BRACKETS <> indicate that you MUST choose one 
of the arguments listed. 



116 



• 



VERTICAL BAR separates iiems in a list of arguments when your 
choices are limited to those arguments listed, and you can t use any 
other arguments. When the vertical bar appears in a list enclosed 
in SQUARE BRACKETS, your choices are limited to the items in 
the list, but you still have the option not to use any arguments 

ELLIPSIS .... a sequence of three dots, means that an option or 
argument can be repeated more than once. 

QUOTATION MARKS " ' enclose character strings, filenames, and 
other expressions. When arguments are enclosed in quotation 
marks in a format, you must include the quotation marks in your 
command or statemient. Quotation marks are not conventions 
used to describe formats; they are required parts of a com- 
mand or statement. 

PARENTHESES () When arguments are enclosed in parentheses 
in a format, you must include the parentheses in your command 
or statement. Parentheses are not conventions used to describe 
formats; they are required parts of a command or statement 

VARIABLE refers to any valid BASIC vanable name, such as X, AS, 
orT%. 

EXPRESSION means any valid BASIC expression, such as A + B-r2 
or,5-(X+3), 



117- 



n 



BASIC 
COMMANDS 

AUTO 



, i 



AUTO {line #\ 

Turns on the automatic line numbering feature which eases the job of 
entering programs by typing the line numbers for you. As you enter 
each program line and press ^'RETURN the next line number Is 
printed on the screen, with the cursor In position to begin typing that 
line- The ( line# | argument refers to the Increment between line num- 
bers AUTO with NO ARGUMENT turns off auto line numbering, as 
does RUN This statemient is executable only In direct mode. 



EXAMPLE 
AUTO 10 
AUTO 50 

AUTO 



automatically 
numbers line in 
increments of len 



automatically 
numbers line in 
increments of fifty 



turns OFF automatic 
line numbering 



I I 



BACKUP BACKUP DoT/i/e* TO Dc/nve# |, ONUum#| 

This command copies all the files on a diskette to another diskette on 
a dual drive system. You can copy onto a new diskette without first 
using the HEADER command to format the new diskette because the 
BACKUP command copies all the information on the diskette, in- 
cluding the formal You should always BACKUP important diskettes in 
case the original is lost or damaged 

Because the BACKUP command also HEADERS diskettes, It destroys 
any information on the diskette onto which you're copying information. 
So If you re backing up onto a previously used diskette, make sure it 
contains no programs you wish to keep. See also the COPY command. 

NOTE This command can only be used with dual disk drives 



EXAMPLE 

BACKUP DO tod: 

BACKUP DO TO Dl, ON U9 - 



Copies all files from 
the disk in drive to 
the disk in drive 1 



Copies all files from 
drive to drive 1 in 
disk drive unit 9 



118 



J 



COLLECT COLLECT|Dcif(i/e#||,ONUon;(#l 

Use this command to free up space altocated to improperly closed 
files and delete references to these files from the directory. 

EXAMPLE: 



COLLECT DO 



CONT 

(Continue) 



CONT 

This command is used to re-start the execution of a program that has 
been stopped by either using the STOP key. a STOP statement, or an ^ 
END statement within the program. The program will resume execution 
where it left off CONT will not work if you have changed or added lines 
of the program (or even just moved the cursor to a program line and hit " 

RETURN without changing anything), if the program stopped due 
to an error, or if you caused an error before trying to re-start the pro- 
gram- The error message in this case is CAN T CONTINUE ERROR 



u 



COPY COPY |Ddrwe#. | '■source file" TO \Ddr!ve#.\"otherlile" \. ON Uunil* 

COPYs a file on the disk in one drive (the source file) to the disk in the 
other on a dual disk drive only, or creates a copy of a file on the same 
drive (with a different file name). 



EXAfVIPLES 

COPY DO. "tesf to D1. test prog" 

COPY DO, "STUFF" TO Dl, "STUFF- 
COPY DO TO Dl 
COPY "WORK. PROG" TO "BACKUP" 



Copies ■■• ■ ■■ 
drive to drive 1, le- 
naming it "tesl prog' 
on drive 1 



Copies -STUFF' from 
dr^ve to drive i 



Copies all files from 
drive to drive 1 



.J 

-J 



Copies 

■WORK PROG 
as a program called 
■BACKUP' on the 
same drive 



119- 



I 1 



DELETE DELETE Itirs! line # | [ - last line#\ 

Deletes lines ot BASIC text. This command can be executed only in 
direct mode. 



n 



n 



n 



EXAMPLES 



DELETE 75 

DELETE 10 - 50 

DELETE - 50 

DELETE -75 



Deletes line 75. 





Deletes lines 10 
through 50 inclusive 










Deletes all lines from 
the beginning of the 
program up to and 
including line 50 





Deletes all lines from 
75 on to the end of 
the program. 



DIRECTORY directory [Ddrive#\ |,Uun/r#J l :iilename"\ 



n 



n 



Displays a disk directory on the Plus/4 screen Use CTRL -S to 
pause the display (any olher key restarts the display after a pause) 
Use the O key (the Commodore key) to slow it down. The 
DIRECTORY command cannot be used to pnnt a hard copy. You 
must load the disk directory (destroying the program currently in 
memory) :o do that. 

EXAMPLES 



DmECTORY 



Lists all files on 
the disk. 



n 



DIRECTORY Dl, U9, "WORK" 



Lists the file on disk 
dnveunit9(8isthe 
default), drive 1, 
named 'work". 



120 



DIRECTORY "AB" 



DIRECTORY DO, "FILE 7.BAK" 



Lists all files starl- 
ing with the letters 
■■AB. like ABOVE. 
ABOARD, etc 



The ?is a wild-card 
that matches any 
single character in 
that position FILE 
1 BAK, FILE2,BAK. 
FILE3 BAKall 
match the stnng 



U 



NOTE: To print out the DIRECTORY of drive 0. unit 8. use 
the following: 

LOAD"$0",8 

OPEN4,4:CMD4:LIST 

PRINT#4:CLOSE4 

DLOAD DLOAD "filename" I. Ddnve#\[,Uunit^] 

This command loads a program from disk into currenl memory (Use 
LOAD to load programs on tape.) You must supply a program name 



EXAfVIPLES: 



DLOAD "BANKRECS" 



DLOAD (A$) 





Searches the disk 
fortne program 
■ BANKRECS- and 
LOADS It 






LOADS a program 
from disk whose 
name is in the variable 
AS You will get an 
erro'if A$ is empty 





The DLOAD command can be used within a BASIC program to find 
and RUN another program on disk, This is called chaining. 



121 



vJ 



n 



n 



n 



DSAVE DSAVE ■'filename" [ .Ddrive#\ l,Uun//#] 

This command stores a program on disk, (Use SAVE to store programs 
on tape.) You must supply a program name 



EXAMPLES 

DSAVE ■■BANKRECS" 

DSAVE (A$) ■ 
DSAVE "PROG 3", D0,U9 



SAVES thie program 
BANKRECStOdisk. 



n 



SAVES to disk pro- 
gram whose name 
IS in the variable AS, 



SAVEs the program 
"PROG 3" to the disk 
drive with a unit num- 
ber (Serial bus ad- 
dress) of 9 



I i 



', i 



HEADER HEADER ■■diskname"\Ji.d.#\ ,Dc/we# l.ON U(./n(f# | 

Before you can use a new diskette for the first lime you must format it 
with the HEADER command. If you want to erase an entire diskette for 
reuse you can use the HEADER command This command divides the 
disk into sections called blocks, and it creates a table of contents, 
called a directory or catalog, on the disk. The diskname can be any 
name up to 16 characters long. The id. number is any 2 characters 
Give each disk a unique i.d. number. Be careful when you HEADER a 
disk because the HEADER command erases all stored data. Giving no 
i.d. number allows you to perform a quick fieader. The old i.d. number 
is used. You can only use Ihe quick header method if the disk was pre- 
viously formatted, since the quick header only clears out the directory 
rather than formatting the disk. 

EXAMPLES: 

HEADER "MYDISK", 123, Dl 
HEADER "RECS", 145, Dl, U8 



n 



122 



HELP HELP 

The HELP command Is used after you gel an error in your program 
When you type HELP. Ihe line where the error occurred is listed, with 
the portion containing the error displayed in flashing characters 

Kgy KEY [key #. string ] 

There are eight (8) function keys available lo the user on the Plus'4 
compuler four unshifted and four shifted The Plus'4 allows you to 
define what each key does when pressed. 

KEY without any parameter specified gives a listing displaying all the 
current KEY assignments The data you assign to a key is typed out 
when that function key is pressed Tine maximum length for all the 
definitions together is 128 characters. Entire commands (or a 
series of commands) can be assigned to a key. For example 

KEY 7, "GRAPHICO' + CHRS(13) + ''LIST' + CHRS(13) 

causes the computer to select text mode and list your program 
whenever the "F?' key is depressed (in direct mode). The CHRS(13) is 
the ASCII character for RETURN Use CHRS(34) to incorporate a 
double quote into a KEY stnng. 

The keys may be redefined in a program For example 

10 KEY 2, -TESTING" - CHRS(34):KEY3. "NO" 
10FORI=lTO8:KEYI,CHR$(I • 132); NEXT 



defines the function 
keys as they are de- 
fined on the Commo- 
dore 64 and VIC 20 



To restore all function keys to their default values, reset the Plus 4 by 
turning it off and on. or press the RESET button. 



123 



LIST '^^ST \ first line*] {-{last !ine#W 



n 



The LIST command lets you look at lines of a BASIC program that have 
been typed or LOADed into the Plus/4'S memory, When used alone 
(without any numbers following it), the Plus/4 gives a complete LISTing 
of the program on your screen, which may be slowed down by holding 
down the <* , key, paused by gtRL-S (unpaused by press- 
ing any other key), o^STOPped by hitting ttie RUN/STOP key. if 
you follow the word LIST with a line number, the Plus/4 only shows that 
line number. If you type LIST with two numbers separated by a dashi, 
the Plus/4 shows all lines from the first to the second line number. If 
you type LIST followed by a number and just a dash, it shows all the 
lines from that number to the end of the program. And if you type LIST, 
a dash, and then a number, you get all the lines from the beginning 
of the program to that line number. Using these variations, you can 
examine any portion of a program, or easily bring lines to the screen 
for modification. 



n 



EXAMPLES: 

LIST 

LIST 100- 

LIST 10 

LIST-100 

LIST 10-200 



n 





Shows entire 
program. 






Shows from line 
100 until the end 
of the program. 






Shows only line 10. 






Shows lines from 
the beginning until 
line 100. 






Shows lines from 
10 to 200, inclusive. 





1 * 



LOAD LOAD [■■///ename" J l,dewce#] [.relocate flag\ 

This is the command to use when you want to use a program stored on 
cassette tape or on disk. If you type just LOAD and hit the :RETURN 
key, the Pius/4 screen goes blank, Press play, and the Plus/4 starts 



124 



looking for a program on the tape. When it finds one, the P!us/4 prints 
FOUND "fflename". You can hit the 0= key to LOAD. Once the pro- 
gram is LOADed, you can RUN, LIST, or change it. 

You can also type the word LOAD followed by a program name, which 
is most often a name in quotes {" program name"). The name may be 
followed by a comma (outside of the quotes) and a number (or numeric 
variable), which acts as a device number to determine where the pro- 
gram is stored (disk or tape). If there is no number given, the Plus/'4 
assumes device number 1, which is the cassette tape recorder. 

The other device commonly used with the LOAD command is usually 
the disk drive, which is device number 8. 



J 



EXAMPLES: 



LOAD 



LOAD "HELLO" 



LOADA$ 



LOAD ■■HELLO' ',8 



Reads in the next 
program on tape 



Searches tape for a 
program called 
HELLO, and LOADS 
if found. 



Looks for a program 
whose name is in the 
variable called A$. 



Looks for the pro- 
gram called HELLO 
on the disk drive, 
or the program 
last accessed. 



The LOAD command can be used within a BASIC program to find 
and RUN the next program on a tape. This is called chaining. 

The RELOCATE FLAG determines where in memory a program is 
loaded. A relocate flag of tells the Plus/4 to load the program at the 
start of the BASIC program area, and a flag of 1 tells it to LOAD from 
the point where it was SAVEd, The default value of the relocate flag is 0. 
This is generally used only when loading machine language programs. 



125 __ 



NEW 



NEW 



n 



t i 



This command erases the entire program in memory and clears out 
any variables that may have been used. Unless the program was 
stored somewhere, it is lost until you type it in again. Be careful when 
you use this command. 

The NEW command can also be used as a statement in a BASIC 
program. When the Plus/4 gets to this line, the program is erased 
and everything stops. This is not especially useful under normal 
circumstances. 

RENAME RENAME [,Ddnve #] -old name" TO "new name" [.Uunit #] 
Used to rename a file on a diskette. 



n 



EXAtvlPLE: 

RENAME 'TEST" TO "FINALTEST" 



Changes the name of 
the file "TEST" to 
■■FINALTEST" 



RENUMBER ^^^^^^^^^^ \ new starting Une #[. increment \. old starting Une #||1 



, i 



71 



The new starting line is the number of the first line in the program after 
renumbering. It defaults to 10. 

The increment is the spacing between line numbers, i.e. 10, 20. 30 etc. 
It also defaults to 10- 

The old starting line number is the line number in the program where 
renumbering is to begin. This allows you to renumber a portion of your 
program. It defaults to the first line of your program. 

This command can only be executed from direct mode. 



EXAMPLES: 



RENUMBER 20, 20, 1 ■ 



Starting at line 65, 
renumbers in incre- 
ments of 10, Line 65 
becomes line 10. 



126 



RENUMBER, .65 



Starting at line 1, 
renumbers the 
program. Line 1 
becomes line 20. 
and ottier lines are 
numbered in incre- 
ments of 20. 



RUN RUN|//ne#] 

Once a program has been typed into memory or LOADed, tlie RUN 
command makes it start working. RUN clears all variables in ttie pro- 
gram before starting program execution. If there is no number follow- 
ing the command RUN, the computer starts with the lowest numbered 
program line. If there is a number following the RUN command execu- 
tion starts at that line. RUN may be used within a program. 



EXAMPLES: 
RUN 

RUN 100 



Starts program 
working from lowest 
line number. 



Starts program at 
line 100. 



SAVE SAVE I "filf^nsme" [ , device # [ ,£07" flag \ |] 

This command stores a program currently in memory onto a cassette 
tape or disk. If you just type the word SAVE and hit RETURN 
the Plus/4 attempts to store the program on the cassette tape. It has no 
way of checking if there is already a program on the tape in that loca- 
tion, so be careful with your tapes. If you type the SAVE command fol- 
lowed by a name in quotes or a string variable name, the Plus.''4 gives 
the program that name, so it may be more easily located and retrieved 
in the future. If you want to specify a device number for the SAVE, fol- 
low the name by a comma (after the quotes) and a number or numenc 
variable. Device number 1 is the tape drive, and number 8 is the disk. 
After the number on a tape command, there can be a comma and a 
second number, which is either or 1 . If the second number is 1 , the 
Plus/4 puis an END-OF-TAPE marker (EOT flag) after your program. If 



127 — 



n 



trying to LOAD a program and the Plus/4 finds one of these markers 
rather Ihan the program you are trying to LOAD, you get a FILE NOT 
FOUND ERROR. 



EXAMPLES: 



SAVE 



I i 



SAVE "HELLO" 

SAVEA$ 

SAVE "HELLO", 8 

SAVE "HELLO", 1,2 



n 





Stores program to 
tape without a name 






Stores on tape with 
the name HELLO 




Stores on tape with 
name in variable AS 




Stores on disk with 
name HELLO 




Stores on tape with 
name HELLO and 
places an END-OF- 
TAPE marker after 
the prog ram 





SCRATCH SCRATCH "file name " [,D drive # ] [ , U unit # ] 

Deletes a file from the disk directory. As a precaution, you are asked 
"Are you sure" before the Plus,'4 completes the operation. Type a Y to 
perform the SCRATCH or type N to cancel the operation. Use this 
command to erase unwanted files, to create more space on the disk. 



EXAMPLE: 

SCRATCH "MY BACK", Dl- 



Erases the file MY 
BACK from the disk 
in drive 1 



n 



n 



VERIFY '^'^'^'^^ "filename" [.device#\ I .relocate flag j 

This command causes the Plus/4 to check the program on tape or disk 
against the one in memory. This is proof that the program you just 
SAVEd is really saved, in case your tape is bad or something isn t 
working. This command is also very useful for positioning a tape so that 
Plus/4 writes after the last program on the tape. All you do is tell the 



128 



Plus/4 to VERIFY the name oi the last program on the tape. It will do so, 
and tell you that the programs don't match (which you already knew}. 
Now the tape is where you want it, and you can store the next program 
without fear of erasing an old one, 

VERIFY without anything after the command causes the Plus/4 to 
check the next program on tape, regardless of its name, against the 
program now in memory, VERIFY followed by a program name (in 
quotes) or a string variable searches the tape for that program and 
then checks. VERIFY followed by a name and a comma and a number 
checks the program on the device with that number (1 for tape. 8 for 
disk). The relocate flag is the same as in the LOAD command, 



EXAfVlPLE: 



VERIFY 



VERIFY "HELLO" 



VERIFY "HELLO ",8,1 





Checks the next pro- 
gram on the tape 




Searches for HELLO 
on tape, checks 
against memory. 






Searches tor HELLO 
on disk, then checks. 





129 



n 



n 



n 



BASIC ^°^ [color source #],a1, b1, a2, b2, [[.angle] [,palnt]] 

STATEMENTS , ^ , ,n...,.-.n 

color source Color source (0-3); default is 1 (foreground 

BOX '^°'°^' 

a1, b1 Corner coordinate (scaled) 

a2, b2 Corner opposite a1 , b1 (scaled); default is 

the PC 
angle Rotation In clocl<wise degrees; default is 

degrees 
paint Paint shape with color (O:off, 1 :on); default 

isO 



This command allows you to draw a rectangle of any size anywtiere on 
the screen. To get the default value, include a comma without entering 
a value. Rotation is based on the center of the rectangle. The Pixel 
Cursor (PC) is left at a2, b2 after the BOX statement is executed. 



EXAMPLES: 
BOXl, 10, 10,60,60 



n 



BOX , 10, 10, 60, 60, 45, 1 
BOX,30, 90, ,45. 1 





Draws the outline of a 
rectangle 


-- 


Draws a filled, rotated 
box (a diamond) 


^ 


Draws a filled, rotated 
polygon 



CHAR ^^^^ [color source #] ,x,y [,text string] [/everse flag] 



n 



n 



Alternate: 

CHAR I co/or source #| ,x,y [,";ex(s(r/rtg"l [, reverse //ag] 

color source Color source (0- 3) 

X Character column (0 - 39) 

y Character row (0 - 24) 

string String to print 

reverse Reverse field flag (0 = off, 1 = on) 



130 



_ J 

Text (alphanumeric strings) can be displayed on any screen at a given ; 

location by the CHAR command. Character data is read from Plus/4 — ^ 
character ROM area. You supply the x and y coordinates of the slarting 

position and the text string you want to display. Color source and re- J 

verse imaging are optional. 



The string is continued on the next line if it attempts to print past the 
right edge of the screen. When used in TEXT mode, the string printed 
by the CHAR command works just like a PRINT string, including re- 
verse field, cursors, flash on/off, etc. These control functions inside the 
string do not work when the CHAR command is used to display text in 
GRAPHIC mode. 

NOTE: when in multicolor mode, to display a character in mufti- 
color 2, set the color source to and reverse flag to 1 . To display 
a character in multicolor 1 , set the color source to and the 
reverse flag to 0. 

CIRCLE CIRCLE Ics] Aa.b] , xr [, [yr] [, [sa] [, [eaj [, [angle] [,/ncj JjJJ 

cs Color source (0 - 3) 

a,b Center coordinate (scaled) 

(defaults to the Pixel Cursor [PC]) 

xr X radius (scaled) 

yr Y radius (default is xr) 

sa Starting arc angle (default 0) 

ea Ending arc angle (default 360) 

angle Rotation in clockwise degrees 

(default is degrees) 
inc Degrees between segments 

(default Is 2 degrees) 



J 





131 _ 



With the CIRCLE command you can draw a circle, ellipse, arc, triangle 
or an octagon. The final coordinate is on the circumference of the 
circle at the ending arc angle. Any rotation is about the center. Set- 
ting the Y radius equal to the X radius does not draw a circle, since the 
X and Y coordinates are scaled differently, Arcs are drawn from the 
starting angle clockwise to the ending angle. The segment increment 
controls the coarseness of the shape, with lower values for inc creating 
rounder shapes. 

EXAMPLES: 



CIRCLE , 160,100,65,10 
CIRCLE , 160,100,65,50 
CmCLE, 60,40, 20,18„„45 
CIRCLE , 260,40,20„„,90 
CIRCLE , 60, 140,20, 18,, ,,120 



Draws an ellipse. 
Draws a circle. 
Draws an octagon. 
Draws a diamond. 
Draws a triangle. 



CLOSE 



CLOSE lile # 

This command completes and closes any files used by OPEN state- 
ments. The number following the word CLOSE is the file number to 
be closed. 



EXAMPLE: 
CLOSE 2 



Logical file 2 is 
closed. 



CLR CLR 



This command erases any variables in memory, but leaves the pro- 
gram itself intact. This command is automaticaliy executed when a 
RUN or NEW command is given, or when any editing is performed. 



Qiyip CMD file # [,ivf/7e list] 

CMD sends the output which normally would go to the screen (i.e. 
PRINT statement. LISTS, but not POKEs into the screen) to another 
device instead. This could be a printer, or a data file on tape or disk. 
This device or file must be OPENed first. The CMD command must 
be followed by a number or numeric variable refernng to the file. 



132 



EXAMPLES: 



OPEN 1.4 



CMDl 



LIST 



PRINT* 1 



CLOSE 1 




OPENS device #4. 
which is Ihe printer. 



All normal output now 
goes to the printer. 



The LISTing goes to 
the printer, not the 
screen — even the 
word READY. 



Set output back to the 
screen. 



Close the file. 



COLOR '-'OLOI^ source #, color # {, luminance #1 
Assigns £ color to one of the 5 color sources: 
Number Source 




1 
2 
3 
4 



background 
foreground 
multicolor 1 
multicolor 2 
border 



if 

-a 
m 



Colors you can use are in the range 1-16 (BLACK. WHITE . . .), As an 
option, you can include the luminance level 0-7, with being lowest 
and 7 being highest. Luminance defaults to 7, Luminance lets you 
select from eight levels of brightness for any color except black. 



DATA '^''^TA list of constants separated by commas 

This statement is followed by a list of items to be used by READ state- 
ments. The items may be numbers or words, and are separated by 
commas. Words need not be inside of quote marks, unless they con- 



133. 



. i 



tain any of the following characters: SPACE, colon, or comma. If two 
commas have nothing between them, the value will be READ as a zero 
for a number, or an empty string. Also see the RESTORE statement, 
which allows the Plus/4 to re-read data. 

EXAMPLE: 

DATA 100, 200, FRED, ' 'HELLO, IVIOM", , 3, 14, ABC123 

Qgp pi^ DEF FN name (variable) = expression 

(DEFine FunctJuN) 



, { 



This command allows you to define a complex calculation as a func- 
„ tion. In the case of a long formula that is used several times within a 

program, this can save a lot of space. The name you give the function 

begins with the fetters FN, followed by any legal numeric variable 
""■ name. First you must define the function by using the statement DEF 

followed by the name you have given the function. Following the name 
-— is a set of parentheses () with a numeric variable (in this case, X) en- 

' ^ closed. Then you have an equal sign, followed by the formula you want 

^ to define. You can "call" the formula, substituting any number for X, 

using the format shown in line 20 of the example below: 



', i 



EXAMPLE: 

10 DEF FNA(X) = 12*{34.75-X/.3) +X ■ 

20 PRINT FNA(7) 



The number 7 is in- 
serted each place X 
is located in the for- 
mula given in the 
DEF statement. 



— ' DIM ^^^'^sriable (subscripts) [,variable(subscnpts)]... 

_ Before you can use an array of variables, the program must first exe- 

r -i cute a DIM statement to establish the DIMensions of that array (unless 

there are 1 1 or fewer elements in the array). The statement DIM is fot- 
' lowed by the name of the array, which may be any legal variable name. 

Then, enclosed in parentheses, you put the number (or numeric vari- 

— able) of elements in each dimension. An array with more than one di- 

mension is called a matrix. You may use any number of dimensions, 
but keep in mind that the whole list of variables you are creating takes 

t] up space in memory, and it is easy to run out of memory if you get car- 

134 



ried away. To figure the number of variables created witfi each DIM, 
multiply the total number of elements in each dimension of the array. 
(Each array starts with element 0.) 

NOTE: Integer (single-digit) arrays take up 2/5ths of the space of 
floating point arrays. 



EXAMPLE: 

10 DIM A${40),B7(15),CC%(4,4,4) 



1 _L 



41 Elements 



16 Elements- 



125 Elements 



DO/ 

LOOP/ 

WHILE/ 

until; 

EXIT 



You can dimension more than one array in a DIM statement by sepa- 
rating the arrays by commas. If the program executes a DIM statement 
for any array more than once, you II get a re'DIMed array error mes- 
sage. It is good programming practice to place DIM statements near 
the beginning of the program 

DO| UNTIL boo/ean argument WHE,E boolean argument] state- 
ments {EXIT] 

LOOP I UNTE. boolean argument WHILE boolean argument | 

Performs the statements between the DO statement and the LOOP 
statement. If no UNTILorWHILE modifies either the DO or the LOOP 
statement, execution of the intervening statements continues indefi- 
nitely. If an EXIT statement is encountered in the body of a DO loop, 
execution is transferred to the first statement following the LOOP 
statement. DO loops may be nested, following the rules defined lor 
FOR-NEXT loops. If the UNTIL parameter is used, the program con- 
tinues looping until the boolean argument is satisfied (becomes 
TRUE), The WHILE parameter is basically the opposite of the UNTIL 
parameter: the program continues looping as long as the boolean 
argument Is TRUE. An example of a boolean argument is A=1. or 
G>=65. 



135 „ 



EXAMPLE: 
DOUNTILX = OORX=1 



LOOP 

DO WHILE A$ = 

A$:LOOP 



:GET 



n 



DRAW DRAW co/or source #[, a 7,5 r fTOa2, t>2...1] 

Witfi tfiis command you can draw individual dots, lines, and shapes, 
You supply color source (0-3), starting {a1 , b1 ) and ending points 
(a2, b2). 



• i 



n 



END 



n 



EXAMPLES: 






. / 

a dot: 


DRAW1, 100, 50— no 
endpoint specified, 
defaults to al.bl 
value for a2,b2 to 
create a dot 




lines : -4 — 
a shape : 


DRAW, 10,10 TO 
DRAW . TO 25,30 
100,60 




"^ 


DRAW, ICIOTO 
10,60 TO 100,60 TO 
10,10 





END 



When [he program executes an END statement, tfie program stops 
RUNning immediately- You may use [he CONT command to re-start the 
prog ram at ttie statement following thie END statement. 



FOR... 

TO... 

STEP 



; i 



FOR variable = start value TO end value [STEP increment] 

This statement works with the NEXT statement to set up a section of the 
program that repeats for a set number of times. You may just want the 
Ptus/4 to count up to a [arge number so the program pauses for a few 



136 



seconds, in case you need something counted, or something must be 
done a certain number of times (such as printing). 

The loop variable is the variable that is added to or subtracted from 
dunng the FOR/NEXT loop. The start value and the end value are the 
beginning and ending counts for the loop variable. 

The logic of the FOR statement is as foilows: First, the loop variable is 
set to the start value. When the program reaches a line with the com- 
mand NEXT, it adds the STEP increment (default = 1 ) to the value of 
the loop variable and checks to see if it is higher than the end of loop 
value. If It is not higher, the next line executed is the statement im- 
mediately following the FOR statement. If the loop variable is larger 
than the end of loop number, then the next statement executed is the 
one following the NEXT statement. See also the NEXT statement, 

EXAMPLE: i 

10 FOR L = 1 TO 10 j 

20 PRINT L I 
30 NEXT L 

40 PRINT "I'M DONE! L = "L j 

This program prints the numbers from one to ten on the screen, fol- 
lowed by the message I'M DONE! L = 1 1 . 

The end of loop value may be followed by the word STEP and another 
number or variable. In this case, the vaiue following the STEP is added 
each time instead of one. This allows you to count backwards, by frac- 
tions, or any way necessary. 

You can set up loops inside one another. This is known as nesting 
loops. You must be careful to nest loops so that the last loop to start is ' 
the first one to end. 



_J 



EXAMPLE OF NESTED LOOPS: 
10 FOR L = 1 TO 100 "X 

20FORA= 5T0 11STEP2 j-^ 
30 NEXT A j 

40 NEXT L J 



This FOR... NEXT 
loop is "nested" in- 
side the larger one 



137 



n 



n 



GET GET variable list 

The GET statement is a way to get data from the keyboard one 
character at a time. When the GET is executed, the character that 
was typed is received, if no character was typed, then a null (empty) 
character is returned, and the program continues without waiting for 
a key. There is no need to hit the .RETURN ' key, and in fact the 
i RETUHN key can be received with a GET. 

The word GET is followed by a variable name, usually a string variable. 
If a numeric were used and any key olher than a number was hit, the 
program would stop with an error message. The GET statement may 
also be put into a loop, checking for an empty result, which waits for 
a key to be struck to continue. The GETKEY statement could also 
be used in this case. This command can only be executed within 
a program. 



n 



EXAMPLE: 


This line waits for the 




10 GET A$:IF A$ <> "A" THEN 10 -4 — 


A key to be pressed 
!o continue, 

._i 





n 



Qg JK^Y GETKEY variable list 

The GETKEY statement is very similar to the GET statement. Unlike 
the GET statement, GETKEY waits for the user to type a character 
on the keyboard, This lets it be used easily to wait for a single char- 
acter to be typed. 

This command can only be executed within a program. 



n 



GET# 



n 



EXAIVIPLE: 

10 GETKEY A$ 



This line waits for 
a key to be struck. 
Typing any key 
will continue the 
program. 



GET# file number.variable list 

Used with a previously OPENed device or file to input one character at 
a time. Otherwise, it works like the GET statement. This command can 
only be executed within a program. 



138 



EXAMPLE: 
GET#1,A$ 



GOSUB GOSUBftie# 



This statement is like the GOTO statement, except that the Plus/4 re- 
members where it came from. When a line with a RETURN statement is 
encountered, the program jumps back to the statement immediately 
following the GOSUB, The target of a GOSUB statement is called a 
subroutine. A subroutine is useful if there is a coutine in your program 
that can be used by several different portions of the program. Instead 
of duplicating the section of program over and over, you can set it up 
as a subroutine, and GOSUB to it from the different parts of the pro- 
gram. See also the RETURN statement. 



EXAf\/IPLE; 

20 GOSUB 800 



GOTO 

or GO TO 



means go to the 
subroutine begin- 
ning at line BOO 
and execute it. 



800 PRINT "HI THERE" ;RETURN 



GOTO line # 

After a GOTO statement is executed, the next line to be executed wil 
be the one with the line number following the word GOTO. When used 
in direct mode. GOTO line # allows you to start execution of the pro- 
gram at the given line number without clearing the variables. 

EXAMPLE: 



10 PRINT' ■COMMODORE' 
20 GOTO 10 ^-— 



The GOTO in line 20 
makes line 10 repeal 
continuously until you 
press RUN/STOP 



GRAPHIC GRAPHIC <mode l.clear option | ; CLR > 

This statement puts the Plus/4 in one of its 5 graphic modes: 



139 



n 



mode description 



normal text 

1 liigli-resolution graphics 

2 liigln-resolutron graplnics. split screen 

3 multicolor graphics 

4 multicolor graptiics, split screen 



[.., 



IF... 

THEN 

:ELSE] 



n 



When executed, GRAPHIC 1-4 allocates a 10K bit-mapped area, 
and the start of the BASIC text area is moved above the hi-res area. 
This area remains allocated even if the user returns to TEXT mode 
(GRAPHIC 0). If 1 is given in the GRAPHIC statement as the second 
argument, the screen is also cleared. Executing a GRAPHIC CLR 
command de-allocates the 10K bit-mapped area, and makes it avail- 
able once again for BASIC text and variables. 

IF expression THEN then-clause | :ELSE else-clause \ 

IF... THEN lets the computer analyze a BASIC expression preceded 
by IF and take one of two possible courses of action. If the expression 
is true, the statement following THEN is executed. This expression may 
be any BASIC statement. If the expression is false, the program goes 
directly lo the next line, unless an ELSE clause is present. The expres- 
sion being evaluated may be a variable or formula, in which case it is 
considered true if nonzero, and false if zero. In most cases, there is an 
expression involving relational operators ( = , <, >, < = , > = , <>, 
AND, OR. NOT). 

The ELSE clause, if present, must be in the same line as the IF-THEN 
part. When an ELSE clause is present, it is executed when the THEN 
clause isn't executed. In other words, the ELSE clause executes when 
the IF expression is FALSE. 

Tlion 



n 





11 


No ^^ 


Prini 
OK- 




C!-.eck 
■X -■ 0" 








Else 




End 







140 



^ 



EXAMPLE: 






Checks the value of 


50 IF X>0 THEN PRINT "OK" :ELSE END 


X. If X is greater than 




0, the THEN clause 




is executed, and the 




ELSE clause isn't. If 




X is less than 0, the 




ELSE clause is exe- 




cuted and the THEN 




clause isn't. 



INPUT ^NPUT {prompt string: ] variable list 

The INPUT statement allows the computer to ask for data from the per- 
son running the program and place it into a variable or vanables. The 
program stops, prints a question mark (?) on the screen, and waits for 
the person to type the answer and hit the return .i key, 

The v*/ord INPUT is followed by a variable name or list of variable 
names separated by commas, There may be a message inside of 
quotes before the list of variables to be input. If this message {called 
a promp!) is present, there must be a semicolon (;) after the closing 
quote of the prompt. When more than one variable is to be INPUT, they 
should be separated by commas when typed in. If not, the computer 
asks for the remaining values by printing two question marks (??). If 
you press the "ftETUrat-;} key without INPUTting a value, the INPUT 
variable retains the value previously input for that variable. This state- 
ment can only be executed within a program. 

EXAMPLE: 

10 INPUT "PLEASE TYPE A NUMBER" ; A 

20 INPUT "AND YOUR NAME"; AS 

30 INPUT B$ 

40 PRINT"BET YOU DIDN'T KNOW WHAT I WANTED! " 



INPUT# 



INPUT* file number, variable list 

This works like INPUT, but takes the data from a previously OPENed 
file or device. No prompt string is allowed. This command can only 
be used in program mode. 

EXAfvlPLE: 
INPUT#2,A$, C, D$ 



.■-J 



141 -- 



LET ILETl var/ab/e expression 

The word LET is hardly ever used in programs, since it is not neces- 
sary, but the statement itseK is the heart of all BASIC programs^ When- 
ever a variable is defined or given a value, LET is always implied. The 
variable name which is to get the result of a calculation is on the left 
side o! the equal sign, and the number or formula is on the right side. 

EXAMPLE; 

10 LET A = 5 

20B = 6 

30C = A'B + 3 

40D$= "HELLO" 



n 



n 



LOCATE LOCATE x-coordinate. y-coordinate 

The LOCATE command lets you put the pixel CUfSOf (PC) anywhere 
on the screen. The PC is the current location of the starling point of the 
next drawing. Unlike the regular cursor, you can't see the PC, but you 
can move it with the LOCATE command. For example: 

LOCATE 160, 100 

positions the PC in the center of the high resolution screen. You won't 
see anything until you actually draw something. You can find out 
where the PC is at any time by using the RDOT(O) function to get the 
X-coordmate and RDOT(I) to gel the Y-coordinate. The color source 
of the dot at the PC can be found by printing RD0T(2). (In all drawing 
commands where a color option is available, you may selec* a value 
from to 3, corresponding to the background, foreground, multicolor 
1, or multicolor 2 as the color source.) 

MONITOR ^omroR ~^— 

This command takes you out of BASIC into (he built-in machine lan- 
guage monitor programi. The monitor is used to develop, debug, and 
execute machine language programs more easily than from BASIC. 
See the section on monitor commands for more information. (When 
in the monitor, typing an X and hlttinc return - gets you back 
to BASIC.) 



142 



NEXT NEXT [variable variable] 

The NEXT statement is used with the FOR statement. When the com- 
puter encounters a NEXT statement, it goes back to the corresponding 
FOR statement and checks the loop variable. (See FOR statement for 
more detail.) If the loop is finished, execution proceeds with the state- 
ment after the NEXT statement. The word NEXT may be followed by a 
variable name, a list of variable names separated by commas, or no 
variable names. If there are no names listed, the last loop started is the 
one being completed. If the variables are given, they are completed in 
order from left to nght. 

EXAMPLE: 

10 FOR L = ITO lOiNEXT 

20 FOR L = 1 TO 10:NEXT L 

30 FOR L = ITO 10:PORM = 1 TO 10: NEXT M, L 

Q|l| ON expression <GOTO,'GOSUB> line #T [, line #2, , , , J 

This command can make the GOTO and GOSUB statements into spe- 
cial versions of the IF statement. The word ON is followed by a formula, 
then either GOTO or GOSUB, and a list of line numbers separated by 
commas, if the result of the calculation of the formula (expression) is 
1, the first line in the list is executed. If the result is 2, the second line 
number is executed, and so on. If the result is 0, or larger than the 
number of line numbers in the list, the next line executed is the state- 
ment following the ON statements. If the number is negative, an 
ILLEGAL QUANTITY ERROR results, 

EXAMPLE: WhenX=1.0N 

sends control to the 
10 INPUT X:rF X- THEN 10 first line number in 

the lisl 
20 ON X GOTO 50, 30, 30, 70 

When X = 2, ON 
25 PRINT "FELL THROUGH":GOTO 10 sends control to the 

second line (30), etc, 
30 PRINT -TOO HIGH" :GOTO 10 

50 PRINT "TOO LOW' ' : GOTO 10 

70 END 



143 



a 



OPEN OPEN file #, device # [.secondary address ] [."filename, type, mode"] 



I * 



The OPEN statement allows the Plus/4 to access devices such as the 
cassette recorder and disk for data, a printer, or even the screen of the 
Plus/4. The word OPEN is followed by a logical file number, which is the 
number to which all other BASIC statements will refer. This number is 
from 1 to 255. There is always a second number after the first called the 
device number. Device number is the Plus/4 keyboard, 3 is the Plus/4 
screen, 1 is the cassette recorder, 4 is the printer, 8 is usually the disk. 
A zero (0) may be included in front of the device number digit (e.g., 08 
(or 8, which are interchangeable for the Plus/4). It is often a good idea 
to use the same file number as the device number because it makes it 
easy to remember which is which. Following the second number may 
be a third number called the secondary address. In the case of the 
cassette, this can be for read, 1 for write, and 2 for write with end- 
ol-tape marker at the end. In the case o( the disk, the number refers to 
the channel number. In the printer, the secondary addresses are used 
to set the mode of the printer. See the Plus/4 Programmer's Reference 
iVlanual or the manuH' for each specific device for more information for 
more on secondary addresses. There may also be a string following 
the third number, which could be a command to the disk drive or the 
name of the file on tape or disk. The type and mode refer to disk files 
only. (File types are prg.seq, rel, and usr; modes are read and write.) 



n 



EXAMPLES: 

10 OPEN 3,3 

10 OPEN 1.0 

20 OPEN 1,1,0, "DOT" 

OPEN 4,4 

OPEN 15,8,15 



n 



-^ 


OPENS the SCREEN 
as a device. 




OPENS the keyboard 
as a device. 




-^ 


OPENS the cassette 
for reading, file to be 
searched for is 
named DOT 


^ 


OPENS a channel to 
use the printer. 


"V 


OPENS the command 
channel on the disk. 



144 



5 OPEN 8,8,12,"TESTFILE,SEQ,WRITE"'* creates a sequential disk 

file for writing. 

See also: CLOSE, CMD, GET#, INPUT#, and PRINT# statements, ^ 
system variable ST, DS, and DSS. 

PAINT PAINT [co/or source J L [a, t)]L mo de ] ] — ^ 

Color source (0-3); (default is 1 , foreground color) 9 

a,b starting coordinate, scaled {default is at the PC) 

mode = paint an area defined by tfie color ^ 

source selected 

1 = paint an area defined by any non- ^ 

background source " 

The PAINT command lets you fill an area with color It fills in the area ■ 

around the specified point until a boundary of the same color (or any 

non-background color, depending on which mode you have chosen) J 
is encountered. 

The final position of the PC will be at the starting point (a,b). M 

NOTE: If the starting point is already the color of color source — J 

you name (or any non-background when mode 1 is used), there 

is no change. j 

EXAMPLE: , ^ 
10 CIRCLE. 160.100,65,50- 



draws outline of c:rcle 




20 PAINT , 160,100 



fills :n the circle 
with color 




145 



POKE POKE address, value 

The POKE command allows you to change any value in the Plus/4 RAM 
memory, and lets you modify many of the Plus/4 Input/Output registers. 
POKE is always followed by two numbers, (or equations). The first 
number is a location inside the Ptus/4 memory. This could have any 
value from to 65535. The second number is a value from to 255, 
which is placed in the location, replacing any value that was there 
previously. 

EXAMPLE: 

10 POKE 28000,8 -« 



20 POKE 28*1000,27 



Sets location 28000 
to 8. 



Sets location 28000 
to 27. 



Note: PEEK is listed under FUNCTIONS. 



PRINT P^^^"^ printlist 



The PRINT statement is the major output statement in BASIC, While the 
PRINT statement is the first BASIC statement most people learn to use, 
there are many subtleties to be mastered here as well. The word PRINT 
can be followed by any of the following: 

Characters inside of quotes ("text lines") 

Variable names (A, B, AS, XS) 

Functions (SIN(23), ABS(33)) 

Punctuation marks (; ,) 

The characters inside of quotes are often called literals because they 
are printed exactly as they appear. Variable names have the value 
they contain (either a number or a string) pnnted. Functions also have 
their number values printed. Punctuation marks are used to help for- 
mat the data neatly on the screen. The comma divides the screen into 
4 columns for data, while the semicolon doesn't add any spaces. 
Either mark can be used as the last symbol in the statement. This re- 
sults in the next PRINT statement acting as if it is continuing the last 
PRINT statement. 



146 



EXAMPLE: 



J 



10 PRINT "HELLO" 

20 A$ = "THERE" :PRINT "HELLO, "AS 

30 A = 4:B = 2:PRINTA^B 

50 J=41 :PRINT J; :PRINT J-1 

60C=A+B:D=A-B:PRINTA;B:C,D 



RESULT 

HELLO 

HELLO, THERE 

6 

41 40 

4 2 6 



See also: POS(). SPC(), and TAB() FUNCTIONS. 



PRINT # PRINT# We #, print list 

There are a few differerices between this statement and the PRINT. 
First of all. the word PRINT# is followed by a number, which refers to 
the device or data file previously OPENed. The number is followed by a 
comma, and a list of things to be PRlNTed. The comma and semicolon 
act in the same manner for spacing as they do in the PRINT statement. 
Some devices may not work with TAB and SPC. 

EXAMPLE: 

100 PRINT#1, "HELLO THEREI",A$,B$, 



PRINT 
USING 



PRINT [ # fllenumber \ USING format list: print lis t: 

These statements let you define the format of string and numeric items 
you want to print to the screen, printer, or another device. Put the for- 
mat you want in quotes. This is the format list. Then add a semicolon 
and a list of what you want printed in the format for the print list. The list 
can be variables or the actual values you want printed. For example: 

5X = 32: Y=100.23: A$ = "CAT" 
10 PRINT USING "$##.##";13.25,X,Y 
20 PRINT USING "###>#";"CBM",A$ 



^ 



When you RUN this, line 10 prints out: 



$13.25 S32.00 $• 



prints •••'* instead 
of Y value because 
Y has 5 digits, which 
does not conform to 
format list (as ex- 
plained below) 



_J 



3 



147 











Line 20 prints this: 


(eaves three spaces 




"^^BM CAT 


before printing 
"CBM" as defined in 
format list 








CHARACTER 


NUMERIC 


STRING 


Pound Sign (#) 


X 


X 


Plus( + ) 


X 




Minus {-) 


X 




Decimal Point (.) 


X 




Comma (.) 


X 




Dollar Sign (S) 


X 




Four Carets (It It ) 


X 




Equal Sign ( = ) 




X 


Greater Than Sign {>) 




X 



n 



Tfie pound sign (#) reserves room for a single character in the output 
field. If the data item contains more characters than you have # in your 
format field, the following occurs: 

• For a numeric item, the entire field is filled with asterisks ("). 
No numbers are printed. 

For example: 

10 PRINT USING "####",X 

For these values for X, this format displays: 

A =12.34 12 

A = 567.89 568 

A = 123456 •*♦• 

For a STRING item, the string data is truncated at the bounds of the 
field. Only as many characters are printed as there are pound signs 
{#) in the format item. Truncation occurs on the right. 

The plus (+)and minus (-) signs can be used in either the first or last 
position of a format field but not both. The plus sign is printed if the 
number is positive. The minus sign is printed if the number is negative. 



148 



II you use a minus sign and the number is positive, a biank is printed 
in the cliaracter position indicated by the minus sign. 

If you don't use either a plus or minus sign in your format field for a 
numeric data item, a minus sign is printed before the first digit or 
dollar symbol if the number is negative and no sign is printed if the 
number is positive. This means that you can print one character more 
if the number is positive. If there are too many digits to fit into the 
field specified by the # and + /- signs, then an overflow occurs 
and the field is filled with asterisks {*), 

A decimal point (.) symbol designates the position of the decimal point 
in the number. You can only have one decimal point in any format field. 
It you don't specify a decimal point in your format field, the value is 
rounded to the nearest integer and printed without any decimal places. 

When you specify a decimal point, the number of digits preceding the 
decimal point (including the minus sign, if the value is negative) must 
not exceed the number of # before the decimal point. If there are too 
many digits an overflow occurs and the field is filled with asterisks {*). 

A comma (,) lets you place commas in numeric fields. The position of 
the comma in the format list indicates where the comma appears in a 
phnted number. Only commas within a number are printed. Unused 
commas to the left of the first digit appear as the filler character. At 
least one # must precede the first comma in a field. 

If you specify commas in a field and the number is negative, then a 
minus sign is printed as the first character even if the character posi- 
tion is specified as a com.ma. 



_J 



EXAMPLES: 




FIELD 


EXPRESSION 


RESULT 


##.# + 


-.01 


0.01- 


##.#- 


1 


1.0 


#### 


-100.5 


-101 


#### 


-1000 


** ** 


###. 


10 


10. 


#S## 


1 


SI 



COMMENT 

Leading zero added. 
Trailing zero added. 
Rounded to no decimal places. 
Overflow because four digits 
and minus sign cannot fit infield. 
Decimal point added. 
Leading Ssign. 



A dollar sign ($) symbol shows that a dollar sign will be phnted in the 
number, If you want the dollar sign to float (always be placed before 



149 



the number), you must specify at least one # before ttie dollar sign. If 
you specify a dollar sign without a leading #, the dollar sign is printed 

— in the position shown in the format field. If you specify commas and/or 

a plus or minus sign in a format field with a dollar sign, your program 

_ prints a comma or sign before the dollar sign. 

The four up arrows or carets (tTTt) symbol is used to specify that the 

— number is to be printed in E + format. You must use # in addition to the 

tTTt to specify the field width. The ttTT can appear either before or 

^ after the # in the format field. 

■ ' You must specify four carets (tltl) when you want to print a number in 

« E - format (scientific notation). If you specify more than one but fewer 

than four carets, you get a syntax error If you specify more than four 
carets only the first four are used. The fifth caret is interpreted as a no 
text symbol. 

_ An equal sign ( = ) is used to center a stnng in the field. You specify the 

, J field width by the number of characters (# and =) in the format field. If 

the string contains fewer characters than the field width, the string is 
~~ centered in the field. If the string contains more characters than can be 

fit into the field, the right-most characters are truncated and the string 

— fills the entire field. A greater than sign (>) is used to right justify a 

string in a field. You specify the field width by the number of characters 

^_ (# and =) in the format field. If the string contains fewer characters 

I 3 than the field width, the string is right justified in the field. If the string 

contains more characters than can be fit into the field, the right-most 
"^ characters are truncated and the string fills the entire field, 

PUDEF PUDEF "7 ^rtrougft 4 characters" 



'. J 



n 

n 

n 



PUDEF lets you redefine up to 4 symbols in the PRINT USING state- 
ment. You can change blanks, commas, decimals points, and dollar 
signs into some other character by placing the new character in the 
correct position in the PUDEF control string. 

Position 1 is the filler character. The default is a blank. Place a new 
character here when you want another character to appear in place 
of blanks. 

Position 2 is the comma character. Default is a comma. 

Position 3 is the decimal point. 

Position 4 is the dollar sign. 



150 



EXAMPLES: 



lOPUDEF 

20 PUDEF " (II " 

30PUDEF" .," 



40 PUDEF" ..£" 



PRINTS* in the place 
of blanks- 



PRINTs@in place of 
commas- 



PRINTs decimal 
points in place of 
commas, and com- 
mas in place of 
decimal points. 



PRINTS Englisfi 
pound sign in place 
of S, decimal points 
in place of commas, 
and commas in place 
of decimal points. 
Other signs are the 
default values. 



_J 



READ READ variable list 

This statement is used to get information from DATA statements into 
variables, where the data can be used. The READ statement variable 
list may contain both strings and numbers. Care must be taken to avoid 
reading strings where the READ statement expects a number, which 
produces an ERROR message. 

EXAMPLE- 
READ A$, G$, 45 



REM 



REM message 

The REMark is just a note to whoever is reading a LIST of the program. 
It may explain a section of the program, give information about the 
author, etc. REfvli statements in no way affect the operation of the 
program, except to add to its length (and therefore slow it down). 
The word REM may be followed by any text, although use of graphic 
characters gives strange results. 



151 



n 



n 



n 



EXAMPLE: 

10 NEXT X: REM THIS LINE IS UNNECESSARY 
RESTORE RESTORE [line #] 

When executed in a program, ihe poinler to the item in a DATA statement 
wtiich is to be read next is reset to ttie first item in ttie list. This gives you 
the ability to re-READ the information. If a [line #| follows the RESTORE 
statement, the pointer is set to that line. Otherwise the pointer is reset to 
Ihe first DATA statement in the program. 

EXAMPLE: 
RESTORE 200 



n 



n 



n 



RESUME RESUME [line # /NEXT | 

Used to return to execution after TRAPping an error. With no argu- 
ments. RESUME attempts to re-execute the line in which the error 
occurred, RESUME NEXT resumes execution at the next statement 
following the statement containing the error; RESUME line # will 
GOTO the specific line and begin execution there, 

RETURN RETURN 

This statement is always used with the GOSUB statement. When the 
program encounters a RETURN statement, it goes to the statement 
immediately following the last GOSUB command executed. If no 
GOSUB was previously issued, then a RETURN WITHOUT GOSUB 
ERROR message is delivered, and program execution is stopped. 

SCALE SCALE <7/0> 

The scaling of the bit maps in multicolor and high resolution modes can 
be changed with the SCALE command. Entering: 

SCALE 1 

turns scaling on. Coordinates may then be scaled from to 1023 in 
both X and Y rather than the norma! scale values, which are: 



n 



152 



multicolor mode X = 0to159 Y = 0to199 

high resolution mode to 319 to 199 

Scaling can be turned off by entering 'SCALE 0'. 

SCNCLR scNCLR 

Clears the current screen, whether graphics, text, or both 
(split screen). 

SOUND ^'^UND voice #, frequency control, duration 

This statement produces a SOUND using one of three voices with a 
frequency control in the range - 1023 for a duration of - 65535 
eothsof asecond. 

V Voice 



Voice 1 (tone) 
Voice 2 (tone) 
Voice 2 (white noise) 



If a SOUND for voice N is requested, and the previous SOUND for the 
same N is still playing, BASIC waits for the previous SOUND to com- 
plete, SOUND with a duration of is a special case It causes BASIC 
to turn off the current SOUND for that voice immediately, regardless 
of the time remaining on the previous SOUND, See the fVlUSIC NOTE 
TABLE {SECTION 1 1 ) for the frequency control values that correspond 
to real notes. 



EXAMPLE: 
SOUND 2, 800. 360 



Plays a note using 
voice 2 with fre- 
quency set at 800 
for one minute 



SSHAPE/GSHAPE SSHAPE and GSHAPE are used to save and restore rectangular areas 
of multicolor or high resolution screens using BASIC string vanables. 
The command to save an area is: 

SSRAPE string variable, al.bl \.a2.b2] 

string variable String name to save data in _ 



153- 



a1 ,b1 Corner coordinate (scaled) 

a2,b2 Corner coordinate opposite (at ,b1 ) 

(default is the PC) 

Because BASIC limits string lengths to 255 ctiaracters, the size of the 
area you may save Is limited. The string size required can be calcu- 
lated using one of the following (unsealed) formulas: 

L(mcm) = INT ( (ABS(a1 -a2) + 1 ) / 4 + .99) * (ABS(b1 - b2) + 1 ) + 4 
L(h-r) = INT ( (ABS(a1 -a2) + 1 ) / 8 + ,99) * (ABS(b1 - b2) + 1 ) + 4 
(mem) refers to multi-color mode; (h-r) is high resolution. 

The shape is saved row by row. The last four bytes of the string contain 
the column and row lengths less one (i.e.: ABS (at -a2) ) in low/high 
byte format (if scaled divide the lengths by 3.2 (X) and 5.12 (Y) ). 

The command to display a saved shape on any area of the screen: 
GSHAPE string [. [a,b] [.mode] ] 



n 



string Contains shape to be drawn 

a,b Top left coordinate telling where 

to draw the shape (scaled - 
the default is the PC) 

mode Replacement mode: 

0: place shape as is (default) 
1 : place field inverted shape 
2: OR shape with area 
3: AND shape with area 
4: XOl^ shape with area 



EXAMPLES: 
SSHAPE ■'SHIP",0,0 

GSHAPE "SHIP",„1 



Saves shape on screen area from the 
upper left corner to the cursor under the 
name "SHIP" 

Displays inverted "SHIP" shape with the 
top left corner positioned where the cursor 
is located 



154 



STOP STOP 



SYS 



This statement halls the program. A message, BREAK IN LINE #, 
where the # Is the line number containing the STOP. The program 
can be re-started at the statement following STOP if you use the 
CONT command- The STOP statement is usually used while de- 
bugging a program. 

SYS address 

The word SYS Is followed by a decimal number or numeric variable 
in the range to 65535. The program begins executing the machine 
language program starting at that memory location. This is similar 
to the USR function, but does not pass a parameter. See the Plus'4 
Programmer s Reference Guide for information about machine 
language programs. 



TRAP TRAPl//ne#J 



TRON 



_-j 



When turned on, TRAP Intercepts all error conditions (including the 

STOP KEY) except "UNDEF'D STATEMENT ERROR", In Ihe event of 
any execution error, the error flag is set, and execution is transferred 
to the line number named in the TRAP statement. The line number In — ' 
which the error occurred can be found by using the system variable 

EL. The specific error condition is contained in system variable ER. 

The string function ERR${ER) gives the error message correspond- 
ing to any error condition ER. J 

NOTE: An error in a TRAP routine cannot be trapped. ^ 

The RESUME statement can be used to resume execulion. 
TRAP with no line# argument turns off error TRAPplng. 

TRON , 

TRON Is used In program debugging. This statement begins trace 
mode. When you are In trace mode, as each statement executes, the — ■ 
line number of that statement Is printed. 



155- 



TROFF 



VOL 



TROFF 

This statement turns trace mode off. 



1 ) 



I i 



, \ 



VOL volume level 

Sets the current VOLume level for SOUND commands. VOLume 
may be set from to 8, where 8 Is naximumi volume, and Is off. 
VOL affects both voices. 



WAIT w^^"^ address, value 1 [, value 2] 

The WAIT statement is used to halt the program until the contents of a 
location in memory changes in a specific way. The address must be in 
the range from to 65535. Value 1 and value 2 must be in the range 
from to 255. 

The content of the memory location is first exclusive-ORed with value 2 
(if present), and then logically ANDed with value 1 If the result is zero, 
the program checks the memory location again. When the result is not 
zero, the program continues with the next statement. 



156 



MORE ON 

GRAPHIC 

STATEMENTS 



There are a few concepts that apply to all of the bit map graphics 
statements. First is the coricept of the Pixel Cursor (PC). The PC is 
similar to the cjjrsor in text mode: it is the position where the next dot 
is to be drawn. Unlike the text cursor, the PC is invisible. All drawing 
commands use the PC. In addition, the locate command allows you 
to reposition the PC without drawing anything. 

Wherever you would use X,Y coordinates in a drawing command, 
you can use RELATIVE coordinates instead. Relative coordinates are 
based on the current value of the PC To use relative coordinates, jus( 
place a + or - in front of your coordinates. A plus sign before the X 
value moves the PC to the right. A minus sign before the X value moves 
the PC to the left. Similarly a minus sign before the Y coordinate moves 
the PC up, while a plus sign moves the PC down. For example; 



-J 



LOCATE +100,-25 



DRAW1, + 10, + 10X0100,100 



moves the PC nght 
100 pixels and up 25 



draws a line 10 pixels 
right and 10 pixels 
below the current 
value of the PC to the 
absolute point 100,100. 



You can also specify a distance and an angle relative to the current 
PC by separating the two parameters by a semicolon. 

For example: 



LOCATE SO ;45 



moves the PC from 
its current location 
by a distance of 50 
dots at an angle of 
45 degrees. 



157- 



FUNCTIONS Numeric lunctions are classified as such because they return num- 
bers. The functions they perform range from calculating mathennatical 
Nlimprir '^^^^t'Of^s 'o specifying a screen location. Numeric functions follow 

Functions 

FUNCTION (argument) 

where the argument can be a numerical value, variable, or string. 



ABS{X) (absolute value) 

The absolute value function returns the positive value of the 

argument X, 

ASC(X$) 

This function returns the ASCI f code (number) of the first character 

ofXS. 



ATN(X) (arctangent) 

Returns the angle whose tangent is X, measured in radians. 



COS{X) (cosine) 

Returns the value of the cosine of X. where X is an angle measured 

n radians. 

DEC (hexadecimal-string) 

Returns decimal value of hexadecimal-string (0<hexadecimal- 

string<FFFF) 



. ( 



EXAMPLE: 
N = DEC("F4" 
EXP(X) 



Returns the value of the mathematical constant e (2.71828183) raised 
to the power of X. 

FNxx{x) 

Returns the value of the user-defined function xx created in a DBF 

FN XX statement. 



. 1 



INSTR (string 1, string 2 \ starting-position ]) 

Returns position of string 2 in string 1 at or after the Istarting-positionJ. 
The starting-position defaults to the beginning of string 2. If no match is 
found, a value of is returned. 



158 



EXAMPLE il 

PRINT INSTRCTHE CAT IN THE HAT", ■'CAT") 

the result ts 5, because CAT starts at the fifth character in string 1 ^ 

INT(X) (integer) , 

Returns the integer portion of X. wi!h all decimal places to the right ol — ' 
the decimal point removed. The result is always less-than or equal to X, 

Thus, any negative numbers with decimal places become the integer _J 
less-than their current value (e.g. INT(-4.5)= -5). 

If the INT function is to be used for rounding up or down, the fo^m is 
INT(X +;- .5), 



EXAMPLE 

X = INT(X''100+ .5)/100 

Rounds to the next highest penny. 



u 
y 



JOY (n) _ 

When n = 1 Position of loystick # i 

n = 2 Position of joystick #2 — i 

Any value of 128 or more means the fire button is also depressed. The 

direction is indicated as follows — ' 

UP _ 

fire = 128- 1 

8 2 

LEFT 7 3 RIGHT — 
6 4 

5 — 
DOWN 

EXAMPLE " 

JOY(2)=135 y 



joystick #2 fires to the left 

LOG(X) (logarithm) ^ 

This returns the natural log of X, The natural log is log to the base e 

{see EXP(X)). To convert to log base 10, divide by LOG(IO). 



u 



159 — 



I 1 



PEEK(X) 

This function gives the contents of memory location X, where X is 
located in the range of to 65535, returning a result from to 255. 
This Is often used in conjunction with the POKE statement. 



RCLR(N) 

Returns current color assigned to source N {0 < N < 4) 

(0= background, 1 = foreground. 2= multicolor 1.3 = multicolor 

2.4 = border). 

RDOT(N) 

Returns information about the current position of the pixel cursor (PC) 
at XPOS/YPOS. 

N - for XPOS 

1 for YPOS 

2 color source 



RGR(X) 

Returns current graphic mode (X is a dummy argument). 



RLUM(N) 

Returns current luminance level assigned to source N 



RND{X) (random number) 

This function returns a random number between and 1. This is useful 
in games, to simulate dice rolls and other elements of chance, and is 
aiso used in some statistical applications. The first random number 
should be generated by the formula RND(-TI), to start things off dif- 
ferently every time. After this, the number in X should be a 1 , or any 
positive number, {X represents the seed, or what the RaNDom number 
is based on.) If X is zero, RND is re-seeded from the hardware clock 
every time RND is used. A negative value for X seeds the random 
number generator using X and gives a random number sequence. The 
use of the same negative number for X as a seed results in the same 
sequence of random numbers. A positive value gives random numbers 
based on the previous seed. 

To simulate the rolling of a die, use the formula INT{RND(1)*6-H). First 
the random numiber from 0-1 is multiplied by 6, which expands the 
range to 0-6 (actually, greater than zero and less then six). Then 1 is 
added, making the range 1 to under 7. The INT function chops off all 
the decimal places, leaving the result as a digit from 1 to 6. 

To simulate 2 dice, add two of the numbers obtained by the above for- 
mula together. 

160 



J 



J 
J 

.^ 

SGN(X) {sign) 

This function returns the sign, as in positive, negative, or zero, of X. Ttie j 

result is + 1 if positive, if zero, and - 1 if negative. 



EXAMPLE: 

100X = INT(RND(l)*6)+INT(RND(l)*6)+2 
100X=rNT(RND(l)*1000) + l 
100 X = INT(RND(1)' 150) + 100 



Simulates 2 dice. 
Number from 1-1000. 
Number from 100-249. 



SIN(X) (sine) 

This is the trigonometric sine function. The result is the sine of X, where 

Xisan angle in radians. 

SQR(X) (square root) 

This function returns the square root of X, where X is a positive 

number or 0. If X is negative, an ILLEGAL QUANTITY ERROR results. 

TAN(X) (tangent) 

This gives the tangent of X, where X is an angle in radians. 



J 



USR(X) _ 

When this function is used, the program jumps to a machine language 
program whose starting point is contained in memory locations 1281 
and 1282. The parameter X is passed to the machine language pro- — ■ 
gram in the floating point accumulator. Another number is passed back 
to the BASIC program through the calling variable. In other words, this _^ 
allows you to exchange a variable between machine code and BASIC. 
See the Plus/4 PROGRAMfvlER'S REFERENCE GUIDE for more details _____ 
on this, and on machine language programming. 

VAL{X$) _J 
This function converts the string X$ into a number, and is essentially 
the inverse operation from STRS. The string is examined from the left- 
most character to the right, for as many characters as are in recog- ' 
nizable number format. If the Plus/4 finds illegal characters, only the 
portion of the string up to that point is converted. — . 



EXAMPLE: 

10X=VAL("123.456") 

10X = VAL("3E03") 

10 X=VAL("12A13B") -^ 1 x=12 




161- 



10X = VALC*RIUO17*") X = 

10X = VALC'-1,23.23.23") X=-1.23 



StrinQ String functions differ from numeric functions in tfiat ttiey return 
Function^ ctiaracters, graphics or numbers from a string (defined by quotation 
marks) instead of a number, 



CHR$(X) 

This function returns a string ctiaracterwinose ASCII code isX. 

ERRS(N) 

Returns string describing error condition N (see TRAP) 



HEX$(N) 

Returns a 4 cfiaracter string containing the hexadecimal representa- 
tion of value N (0 < N < 65535) 



LEFT$(X$,X) 

This returns a string containing the leftmost X characters of X$. 

LEN(X$) 

Returns the number of characters (including spaces and other 

symbols) in the string X$. 



MIDS(X$,S,X) 

This returns a string containing X characters, starting from the Sth 
character in X$. MIDS can also be used on the left side of assignment 
statement as a pseudo-variable as w/ell as a function. MID$ (string 
variable, starting position, length) = source string. 

This function reassigns values of positions (starting position) through 
(starting position + length) of source string to the characters of string 
variable in corresponding locations. Length defaults to the length of 
string vanables, and an error results if (starting position + length) is 
greater than the length of the source string. 

EXAMPLE: 

10 A$ = "THE DOG IN THE HAT": 

20 PRINT A$ 

30 1VIID$(A$,5,3) = "CAT" 

40 PRINT A$ 



162 



RIGHT$(X$.X) ^ 
This returns the right-most X characters in X$. 

STR$(X) H 
This returns a string which is identical to the PRINTed version of XS^ 

EXAMPLE: * 

A$=STR$(X) M 



Other FRE{x) 

Functions This function returns the number of unused bytes available in memory. ■ j 

X is a dummy argument. — ^ 

POS(X) M 

This function returns the number of the column (0-79) where the next 

PRINT statement begins on the screen. X is a dummy argument. ■ 



SPCtX) 

This is used in the PRINT statement to skip over X spaces. X can have 
a value from 0-255. 



TAB(X) 

This IS used in the PRINT statement. The next item to be printed is in 

column number X. X can have a value from to 255. 



-J 

u 



Tr(PI) 

The 77 symbol, when used in an equation, has the value of 3 14159265. 



163 — 



VARIABLES 
& OPERATORS 



The Plus/4 uses three types of variables in BASIC^ These are; 

normal numeric, integer numeric, and string (alphanumeric) variables. 



I J 



. I 



. 4 



. 4 



i i 



Normal NUMERIC VARIABLES, also called floating point variables, 

VdrisbISS '-^'^ have any value from ^^ to *^°, with up to nine digits of accuracy. 
When a number becomes larger than nine digils can show, as in N"'" 
or N'". the computer displays it in scientific notation form, with the 
number normalized to 1 digit and eight decimal places, followed by the 
letter Eand the power of ten by which the number is multiplied. For 
example, the number 12345678901 is displayed as 1.234356789E+10. 

INTEGER VARIABLES can be used when the number is from +32767 
to -32768, and with no fractional portion. An integer variable is a 
number like 5. 10, or -100, Integers take up less space than floating 
point variables, particularly when used in an array. 

STRING VARIABLES are those used for character data, which may 
contain numbers, letters, and any other character that the Plus/4 can 
make. Ar example of a string variable is "Plus./4". 

VBrisblB Vanable names may consist of a single letter, a letter folowed by a 
NamBS '^'^f^'^®^' 0'' 'wo letters. Variable names may be longer than 2 charac- 
ters, but only the first two are significant. 

An integer variable is specified by using the percent (%) sign after 
the variable name. String variables have the dollar sign (S) after 
their names. 

EXAMPLES: 

Numeric Variable Names: A. A5. BZ 
Integer Variable Names: A%. A5%. BZ% 
String Variable Names: AS. ASS, BZS 

ARRAYS are lists of variables with the same name, using an extra 
number (or numbers) to specify an element of the array. Arrays are 
defined using the DIM statement, and may be floating point, integer, 
or string variables arrays. The array variable name is followed by a 
set of parentheses ( ) enclosing the number of the variable in ihe list. 

EXAMPLES: 
A(7),B2%(11),AS(87) 

Arrays may have more than one dimension. A two dimensional array 



164 



J 



Reserved 

Variable 

Names 



may be viewed as having rows and columns, with the first number 
identifying the row and the second number in the parentheses identi- 
fying the column (as if specifying a certain grid on a map)- 

EXAMPLES: 

A(7,2),BZ%(2,3,4),Z$(3,2) 

There are seven variable names which are reserved for use by the 
PlusM. and may not be used for another purpose. These are the vari- 
ables DS. DSS. ER, EL, ST,TI, and TIS. You also can't use KEYWORDS 
such as TO and IE or any names that contain KEYWORDS, such as 
SRtJN. RNEW, or XLOAD as variable names. 

ST is a status variable for input and output (except normal screen/ 
keyboard operations). The value of ST depends on the results of the 
last input/output operation. A more detailed explanation of ST is in the 
Plus/4 Programmer's Reference Guide, but in general, if the value of 
ST is the operation was sucessful. 

Tl and TIS are variables that relate to the real-time clock built into the 
Plus/4. The system clock is updated every 1/60th of a second. It starts 
at when the Plus/4 is turned on, and is reset only by changing the 
value of Tl$. The variable Tl gives you the current value of the clock in 
1/60ths of a seconds. 

TIS is a string that reads the value of the real-time clock as a 24 hour 
clock The first two characters of TIS contain the hour, the 3rd and 
4th characters are the minutes, and the 5th and 6th characters are 
the seconds. This variable can be set to any value (so long as all 
characters are numbers), and will be automatically updated as a 
24 hour clock. 

EXAIVIPLE: 

TIS = "101530 "sets the clock to 10: 15 and 30 seconds (AM) 

The value of the clock is lost when the Plus/4 is turned off. It starts at 
zero when the Plus,'4 is turned on, and is reset to zero when the value 
of the clock exceeds 235959 (23 hours, 59 minutes and 59 seconds). 

The variable DS reads the disk dnve command channel, and returns 
the current status of the drive. To get Ihis information in words, PRINT 
DSS, These status variables are used after a disk operation, like a 
DLOAD or DSAVE, to find out why the red error light on the disk drive 
is blinking. 



165 



ER. EL, and ERRS are variables used in error trapping routines. They 
are usually only useful within a program. ER returns the last error en- 
countered since the program was RUN, EL is the line where the error 
occurred. ERRS Is a function which allows your program to print one 
of the BASIC error messages. PRINT ERR${ER) prints out the proper 
error message. 



166 



BASIC The ARITHMETIC operators include the following signs: _J 

OPERATORS T ^^^^on 

subtraction L^ 

* multiplication 

/ division m 

t raising to a power (exponentiation) 

On a line containing more than one operator, there is a set order in --J 

which operations always occur. If several operators are used together, 
the computer assigns priorities as follows: First, exponentiation, then ____; 
multiplication and division, and last, addition and subtraction. If two 
operations have the same priority, then calculations are performed in 
order from left to right. If you want these operations to occur in a dif- — ' 

ferent order. Plus./4 BASIC allows you to give a calculation a higher 

priority by placing parentheses around it. Operations enclosed in 

parentheses will be calculated before any other operation. You have 
to make sure that your equations have the same number of left par- 
entheses as righf parentheses, or you will get a SYNTAX ERROR "^ 
message when your program is run. 

There are also operators for equalities and inequalities, called 

RELATIONAL operators Arithmetic operators always take priority 

over relational operators. -^ 



= 


is equal to 


< 


is less than 


> 


is greater than 


<= or =< 


is less than or equal to 


>= or => 


is greater than or equal to 


<> orx 


is not equal to 



Finally, there are three LOGICAL operators, with lower priority than 
both arithmetic and relational operators: 

AND 

OR 

NOT 

These are used most often to join multiple formulas in IF . . . THEN 
statements. When they are used with arithmetic operators, they are 
evaluated last (i.e., after + and -). 



h^ 



167 



, I 



EXAMPLES; 

IFA = B AND C=D THEN 100 
IF A = B OR C = D THEN 100 
A = 5;B=4:PRINTA = B 
A = 5:B = 4:PRINT A>B 



requires both A=B & C=D to be true, 
allows either A=B or C=D to be true, 
displays a value of 
displays a value of -1 



PRINT 123 AND 15:PRINT 5 OR 7 displays 11 and 7 



. J 



: i 



i I 



r J 

n 



168 







SECTION 2 KEYWORD 


ABBREVIATION 


TYPE 






a sHnrr 


IB 


function — numeric 


— 


^^ 1 !■ ASC 


a SHIFT 


iS 


function — numeric 




^^^tjm ^™ 


a fe SHIFT 


iT 


function — numeric 


1 k ■ 1 ^^^° 


a ' SHIFT 


iU 


command 




I 1 ■ ■ BACKUP 


b SHIFT 


iA 


command 




1 1 1. i ^°^ 


b ; SHIFT 


10 


statement 




^ ■ ^ ^ CHAR 


Ch gSHIFT 


lA 


statement 






C 1 SHIFT 


^H 


function— string 




Basic 3.5 CIRCLE 


CfeSHIFT 


J 


statement 




Abbreviations close 


ci|R^Eirr 


iO 

L 
M 


statement 
statement 
statement 




CLR 


C f SHIFT 




CMD 


C f, SHIFT 


COLLECT 


col SHIFT 


L 


command 
statement 




COLOR 


CO ^^^bi 


CONT 


c mmmg 


10 


command 




COPY 


CO SSttBV 


iP 


comnrjand 
function— numeric 




COS 


none 




DATA 


d^BBlFT 


A 


statement 




DEC 


none 




function — numeric 




DEFFN 


dfsairr. 


IE 


statement 




DELETE 


de SHOML 


command 




DIM 


d UBU^fUPH 1 


statement 




DIRECTORY 


di SHIFT 


iR 

|L 


command 
command 
statement 


DLOAD 


d r^^SHIFT 




DO 


none 


DRAW 


d 1 SHIFT 


R 


statement 




DSAVE 




JS 


command 
statement 


END 


e MBIM 




ERRS 


e(HHlFT~iR 


function — string 




EXP 


erSHIFT 


!X 


function — numeric 




FOR 


f SHIFT: !0 


statement 




FRE 


fr.SHIFT 


iR 


function — numeric 




GET 


gifejuirr 


:E 


statement 




GETKEY 


getk*sfflKFT 


jE 


statement 




GET# 


none 




statement 




GOSUB 


gotSHIFT 


IS 


statement 


GOTO 


g'V'SHOSB^O 


statement 




GRAPHIC 


9 mmm 


^R 


statement 


— 






^^^^ 










169 



n 



n 



n 



n 







KEYWORD 


ABBREVIATION 


TYPE 




g 








GSHAPE 


SHIFT 


S 


Statement 


HEADER 


he 


SHIFT 


A 


command 


HEXS 


h 


SHIFT 


z 


function — siring 


IF. ..GOTO 




none 




statement 


IF...THEN...I 


ELSE 


none 




statement 


INPUT 




none 




statement 


INPUT# 


i ' 


*SiSMP* 


N 


statement 


INSTR 


in 


SHIFT 


3 


function — numeric 


INT 




none 




function — numeric 


JOY 


1 


SHIFT 





function — numeric 


KEY 


k 


SHIFT 


~ 


command 


LEFTS 


le 


SHIFT 


F 


function — string 


LEN 




none 




function— numeric 


LET 


1 


SHIFT 


E 


statement 


LIST 


i 


SHIFT 


1 


command 


LOAD 


1 


SHIFT 





command 


LOCATE 


lo 


SHir:^ 

none 


c 


statement 


LOG 






function— numeric 


LOOP 


lo 


SHIFT 





statement 


MIDS 


m 


SHIFT 


1 


function — string 


MONITOR 


m 


SHIFT 





statement 


NEW 




none 




command 


NEXT 


n 


SHIFT 


E 


statement 


ON...GOSUB 


on... go 


SHIFT 


S 


statement 


ON.,,GOTO 


on..,g 


SHIFT 





statement 


OPEN 





SHIFT 


P 


statement 


PAINT 


P 


SHIFT 


A 


statement 


PEEK 


P 


SHIFT 


E 


function— numeric 


POKE 


P 


SHIFT 





statement 


POS 




none 




function— numeric 


PRINT 


7 






statement 


PRINT# 


P 


SHIFT 


R 


statement 


PRINT USING 


?us 


SHIFT 


1 


statement 


PUDEF 


p 


SHIFT 


U 


statement 


RCLR 


r 


SHIFT 


c 


function — numeric 


ROOT 


r 


SHIFT 


D 


function— numeric 


READ 


r 


SHIFT 


E 


statement 


REM 




none 




statement 



170 





^^^^™ 




^^^™ 




'~ 














KEYWORD 


ABBREVIATION 


TYPE 




RENAME 


re 
ran 

re 
res 

re 


SHIFT 


N 
U 
S 
U 
T 
G 


command 
command 
statement 
statement 
statement 
function— numeric 


*"^ 


RENUMBER 


SHIFT 




RESTORE 


SHIFT 


RESUME 


SHIFT 




RETURN 


SHIFT 




RGR 


SHIFT 




RIGHTS 




SHIFT 


1 
L 


function— siring 
function— numeric 


RLUM 


SHIFT 




RND 


s 
so 


SHIFT 


N 
U 
A 
A 


function— numeric 
command 
command 
statement 




RUhJ 


SHIFT 




SAVE 
SCALE 


SHIFT 




SHIFT 




SCNCLR 


s 

sc 

s 

s 


SHIFT 


C 
R 
G 

[ 


statement 
command 
function — numeric 
function — numeric 




SCRATCH 


SHIFT 


SON 


SHIFT 




SIN 


SHIFT 


SOUND 


s 
s 
s 
s 


SHIFT 



P 

Q 
S 


statement 

function— special 

function — numeric 

statement 

reserved — numeric variable 


m 


SPC( 


SHIFT 


SQR 


SHIFT 


a 


SSHAPE 


SHIFT 


STatus 


none 




STOP 


s 


SHIFT 


T 


statement 


u 


STR$ 


St 


SHIFT 


R 


function— string 




SYS 


s 


SHIFT 


Y 


statement 


ii 


TAB( 


t 


SHIFT 


A 


function— special 




TAN 




none 




function — numeric 


— 1 


Tl 




none 




reserved — numeric variable 


Ti$ 




none 




reserved— string variable 




TRAP 


t 


SHIFT 


R 


statement 


•^ 


TROFF 


tro 


SHIFT 


F 


statement 


m 


TRON 


tr 


SHIFT 





statement 


UNTIL 


u 


SHIFT 


N 


statement 


m 


USR 


u 


SHIFT 


S 


function — special 


VAL 




none 




function — numeric 




VERIFY 


V 


SHIFT 


E 


command 


m 


VOL 


V 


SHIFT 





statement 




WAIT 


w 


SHIFT 


A 


statement 


m 


WHILE 


w 


SHIFT 


H 


statement 








^^^_ 







171 



SECTION 3 Converting Standard BASIC Programs To Commodore BASIC 3.5 




Conversion 
Programs 



, 4 



If you have programs written in a BASIC othier than Commodore 
BASIC, some minor adjustments may be necessary before 
running them on the Plus/4. Here are some hints to make the 
conversions easier. 

String Dimensions 

Delete all statements that are used to declare the length oi strings. 
A statement such as DIM A$(1.J). which DIMensions a string array 
tor J elements of length I, should be converted to the Commodore 
BASIC statement DIM A${J). 

Some BASICS use a comma or ampersand for string concatenation 
(linking). Each of these must bechanged to a + sign, which is the 
Commodore BASIC 3.5 operator for string concatenation. 

In Commodore BASIC, the MIDS. RIGHTS, and LEf=T$ functions are 
used to take substrings of strings. Forms such as AS(I) to access the 
Ith character in AS. or AS(I,J) to take a substring of AS from position 
I to J, must be changed as follows: 



. 4 



Other BASIC 

A$(i) = XS 
A$(I,J) = X$ 



Commodore BASIC 3.5 

MID$(AS,I,J) = X$ 
MID$(A$,I,J) = XS 



Multiple Assignments 

To set B and C equal to zero, some BASICs allow statements of the 
form: 10LETB = C =0 

Commodore BASIC would interpret the second sign as a logical 
operator and set B = - 1 if C = 0. Instead, convert this statement to: 
10C =0:B = 

Multiple Statements 

Some BASICS use a backslash {/) to separate multiple statements on a 
line. With 3.5 BASIC, use a colon (:)to separate ail statements. 

Mat Functions 

Programs using the MAT functions available on some BASICs must be 
rewntten using FOR . , . NEXT loops to execute properly. 



172 



■ J 

Reprogramming Function Keys j 

You can reprogram the function keys to match: ttie function keys on the 

Commodore 64 and VIC-20. (This also makes program conversions _J 
from those machines easier). 

To reprogram the keys, put the following line into your program: I 

10FORI=1 T08:KEYI, CHR$(I + 132): NEXT Qj 

Now whenever you type a function key, it sends a non-printing • 

character, from 133 to 140, like the Commodore 64 does. To check for — ^ 
this in a program, you can use this method: 

-J 
20 GETKEY A$: IF ASC(A$) = 133 THEN PRINT "FUNCTION KEY 1 

HIT"; GOTO 20 ' 

30 IF ASC(A$) :• 133 AND ASC(A$) < 141 THEN PRINT "SOME "^ 

OTHER FUNCTION KEY HIT" 

40 GOTO 20 imd 

After your program is done, you have to redefine the keys again if you 
want them to say directory, dioad, etc. You can do this by hand, in a 

program, or by resetting the Plus/4, ; 



U3- 



n 



SECTION 4 These error messages are printed by BASIC. You can also PRINT 
the messages through the use of the ERR$() function. The error 
number refers only to the number assigned to the error for use with 
this function. 



ERROR # ERROR NAME 



\ \ 



^^^^^P 


1 


TOO MANY FILES 


1^ ^^ 


2 


FILE OPEN 


Error Messages 






3 


FILE NOT OPEN 




4 


FILE NOT FOUND 




5 


DEVICE NOT PRESENT 




6 


NOT INPUT FILE 



. \ 



n 



n 



10 



11 



NOT OUTPUT FILE 



MISSING FILE NAME 



ILLEGAL DEVICE 
NUMBER 

NEXT WITHOUT FOR 



SYNTAX 



There is a limit of 10 files 
OPEN at one time. 

An attempt was made to open 
a file using the number of an 
already open file. 

The file number specified in 
an I/O statement must be 
opened before use. 

Either no file with that name 
exists (disk) or an end-of-tape 
marker was read (tape). 

The required I/O device not 
available. 

An attempt made to GET or 
INPUT data from a file that 
was specified as output only. 

An attempt made to send 
data to a file that was speci- 
fied as input only. 

An OPEN, LOAD, or SAVE to 
the disk drive generally re- 
quires a file name. 

An attempt made to use a 
device improperly (SAVE to 
the screen, etc) 

Either loops are nested in- 
correctly, or there is a variable 
name in a NEXT statement 
that doesn't correspond with 
one In a FOR. 

A statement is unrecogniza- 
ble by BASIC. This could be 



174 



12 RETURN WITHOUT 
GOSUB 

13 OUT OF DATA 



14 ILLEGAL QUANTITY 

15 OVERFLOW 

16 OUT OF MEMORY 

17 UNDEF'D STATEMENT 

18 BAD SUBSCRIPT 

19 REDIM'D ARRAY 



20 DIVISION BY ZERO 

21 ILLEGAL DIRECT 



because o1 missing or extra 
parenthesis, misspelled 
keyword, etc. 

A RETURN statement en- 
countered whien no GOSUB 
statement was activs- 

A READ statement en- 
countered, without data 
left unREAD, 

A number used as the 
argument of a function or 
statement is outside the 
allowable range. 

The result of a compu- 
tation is larger than the 
largest number allowed 
(1.701411833E^38) 

Either there is no more room 
for program and program 
variables, or there are too 
many DO, FOR. or GOSUB 
statements in effect. 

A line number referenced 
doesn't exist in the program 

The program tried to refer- 
ence an element of an array 
out of the range specified by 
the DIM statement. 

An array can only be DIMen- 
sioned once. If an array is 
referenced before that array 
is DIM'd. an automatic DIM (to 
10) is performed. 

Division by zero is not allowed. 

INPUT or GET statements are 
only allowed within a program. 



u 



f-i 



175 



22 

23 

24 
25 

26 



TYPE MISMATCH 



STRING TOO LONG 



FILE DATA 

FORMULA TOO 
COMPLEX 



CAN'T CONTINUE 



27 


UNDEF'D FUNCTION 


28 


VERIFY 


29 


LOAD 


30 


BREAK 


31 


CAN'T RESUME 



32 LOOP NOT FOUND 

33 LOOP WITHOUT DO 

34 DIRECT MODE ONLY 

35 NO GRAPHICS AREA 



This occurs when a number 
is used in piace of a string or 
vice-versa, 

A string can contain up to 255 
characters. 

Bad data read from a tape file. 

Simplify the expression 
(break into 2 parts or use 
fewer parentheses}. 

The CONT comn-iand does 
not work if the program was 
not RUN, there was an error, 
or a line has been edited. 

A user defined function refer- 
enced that was never defined. 

The program on tape or disk 
does not match the program 
in memory. 

There was a problem loading. 
Try again. 

The stop key was hit to halt 
program execution. 

A RESUME statement en- 
countered without TRAP 
statement in effect 
The program has encoun- 
tered a DO statement and 
cannot find the correspond- 
ing LOOP 

LOOP encountered without a 
DO statement active. 

This command is allowed 
only in direct mode, not from 
a program. 

A command (DRAW, BOX, 
etc.) to create graphics 
encountered before the 



176 



GRAPHIC command 
was executed. 

36 BAD DISK An attempi failed to HEADER 

a diskette, because the quick 
header method (no ID) was 
attempted on an unformatted 
diskette, or the diskette is bad. 



m 
m 



177 



, 4 



DESCRIPTION 

OF 

DOS 

ERROR 

MESSAGES 



These error messages are returned through the DS and DS$ 
reserved variables. 



NOTE: Error message numbers less than 20 should be ignored 
with the exception of 01 , which gives information about the num- 
ber of files scratched with the SCRATCH command. 




20 



21 



22 



23 



24 



READ ERROR 

(block header not found) 



READ ERROR 

(no sync character) 



READ ERROR 

(data block not present) 



READ ERROR 

(checksum error 
in data block) 



READ ERROR 

(byte decoding error) 



The disk controller is unable to lo- 
cate the header of the requested 
data block. Caused by an illegal 
sector number, or the header has 
been destroyed. 

The disk controller is unable to 
detect a sync mark on the desired 
track. Caused by misalignment of 
the read/writer head, no diskette 
is present, or unformatted or im- 
properly seated diskette. Can 
also indicate a hardware failure. 

The disk controller has been re- 
quested to read or verify a data 
block that was not properly writ- 
!en. This error message occurs 
in conjunction with the BLOCK 
commands and indicates an ille- 
gal track and/or sector request. 

This error message indicates that 
there is an error in one or more of 
the data bytes. The data has been 
read into the DOS memory, but 
the checksum over the data is in 
error. This message may also in- 
dicate grounding problems, 

The data or header has been read 
into the DOS memory, but a hard- 
ware error has been created due 
to an invalid bit pattern in the data 



178 



25 



26 



WRITE ERROR 

(write-verify error) 



WRITE PROTECT ON 



27 



28 



READ ERROR 

(checksum error 
in header) 



WRITE ERROR 

(long data block) 



29 



DISK ID MISMATCH 



30 



SYNTAX ERROR 

(general syntax) 



byte. This message may also 
indicate grounding problems 

This message is generated if the 
controller detects a mismatch 
between the written data and the 
data in the DOS memory. 

This message is generated when 
the controller has been requested 
to write a data block while the 
write protect switch is depressed. 
Typically, this is caused by using 
a diskette with a write protect 
tab over the notch 

The controller has detected an 
error in the header of the re- 
quested data block. The block 
has not been read into the DOS 
memory. This message may also 
indicate grounding problems. 

The controller attempts to detect 
the sync mark of the next header 
after writing a data block. If the 
sync mark does not appear within 
a pre-determined time, the error 
message is generated. The error 
IS caused by a bad diskette format 
(the data extends into the next 
block), or by hardware failure. 

This message is generated when 
the controller has been requested 
to access a diskette which has 
not been initialized. The message 
can also occur if a diskette has a 
bad header. 

The DOS cannot interpret the 
command sent to the command 
channel. Typically, this is caused 



-J 



-J 
Li 



179 _ 



n 



n 



n 



n 



31 

32 
33 
34 



39 



50 



51 



SYNTAX ERROR 

(Invalid command) 

SYNTAX ERROR 

(invalid command) 

SYNTAX ERROR 

(invalid tile name) 

SYNTAX ERROR 

(noiilegivenj 



SYNTAX ERROR 

(invalid command) 



by an illegal number of file names, 
or patterns are illegally used. For 
example, two file names may 
appear on the left side of tfie 
COPY command. 

Tfie DOS coes not recognize tfie 
command. Tfie command musl 
start in thie first position, 

Tfie command sent is longer tfian 
58 cfiaracters. 

Pattern matcfiing is invalidly used 
in tfie OPEN or SAVE command. 

Tfie file name was left out of a 
command or tfie DOS does not 
recognize A as such. Typically, 
a colon(:) has been left out of 
the command. 

This error may result if the com- 
mand rent to command cfiannel 
(secondary address 15) is unrec- 
ognized by the DOS. 



^ i 



RECORD NOT PRESENT Result of disk reading past the 

last record through INPUT#, or 
GET# commands. This message 
will also occur after positioning to 
a record beyond end of file in a 
relative file If the intent is to ex- 
pand the file by adding the new 
record (with a PRINT# com- 
mand), the error message may be 
ignored , INPUT or GET should not 
be attempted after this error is de- 
tected without first repositioning. 

OVERFLOW IN RECORD PRINT# statement exceeds 

record boundary, Information is 
truncated. Since the carriage re- 



180 



u 



52 



60 



61 



FILE TOO LARGE 



WRITE FILE OPEN 



FILE NOT OPEN 



62 
63 

64 

65 



FILE NOT FOUND 
FILE EXISTS 

FILE TYPE MISMATCH 

NO BLOCK 



turn which is sent as a record ter- 
minator is counted in the record 
size, this message will occur if the 
total characters in the record (in- 
cluding the final carriage return) 
exceeds the defined size. 

Record position within a relative 
file indicates that disk overflow 
will result. 

This message is generated 
when a write file that has not 
been closed is being opened 
for reading. 

This message is generated when 
a file is being accessed that has 
not been opened in the DOS. 
Sometimes, in this case, a mes- 
sage is not generated: the re- 
quest is simply ignored 

The requested file does not exist 
on the indicated drive. 

The file name of the file being 
created already exists on the 
disl<ette. 

The file type does not match the 
file type in the directory entry for 
the requested file. 

This message occurs in conjunc- 
tion with the B-A command. It 
indicates that the block to be allo- 
cated has been previously allo- 
cated. The parameters indicate 
the track and sector available 
with the next highest number. If 
the parameters are zero (0), then 
all blocks higher in number are 
in use. 



181 



66 



67 



ILLEGAL TRACK 
AND SECTOR 



ILLEGAL SYSTEM 
TORS 



The DOS has attempted to ac- 
cess a track or block which does 
not exist in the format being used. 
This may indicate a problem read- 
ing the pointer to the next block. 

This special error message 
indicates an illegal system 
track or sector. 



70 



NO CHANNEL 

(available) 



71 



DIRECTORY ERROR 



72 



DISK FULL 



•- 1 



The requested channel is not 
available, or all channels are in 
use. A maximum of five sequential 
files may be opened at one time to 
the DOS. Direct access channels 
may have six opened tiles. 

The BAM does not match the 
internal count. There is a problem 
in the BAM allocation or the BAM 
has been overwritten in DOS 
memory. To correct this problem 
reinitialize the diskette to restore 
the BAM in memory. Some active 
files may be terminated by the 
corrective action. NOTE: BAM = 
Block Availability Map 

Either the blocks on the diskette 
are used or the directory is at its 
entry limit. DISK FULL is sent 
when two blocks are available 
on the 1541 to allow the current 
file to be closed. 



73 DOS MISMATCH (73, 

CBMDOSV2.6 1541) 



V i 



DOS 1 and 2 are read compatible 
but not write compatible. Disks 
may be interchangeably read with 
either DOS. but a disk formatted 
on one version cannot be written 
upon with the other version be- 
cause the format is different. This 
error is displayed whenever an 



182 



attempt is made to write upon a 
dtsl< which has been formatted in 
a non-comp;i'ible format, (A utility 
routine is available to assist in 
converting from one format to 
anotlier) Thiis message may also 
appear after power up, 

74 DRIVE NOT READY An attempt has been made to 

access the Floppy Disk Drive 
witfiout any disl<ette present. 



U 



183" 



SECTIONS Introtiuclion 

TEDMON is a built-in machine language program which lets you easily 
write machine language programs. TEDMON includes a machine lan- 
guage monitor, a mini assembler, and a disassembler. 

Machine language programs written using TEDMON can run by them- 
selves, or be used as very fast 'subroutines' for BASIC programs since 
TEDMON has the ability to coexist peacefully with BASIC. 



B 




Tedmon 
Commands 


A 
C 

D 


ASSEMBLE 
COMPARE 

DISASSEMBL 




F 


FILL 




G 


GO 




H 


HUNT 




L 


LOAD 




M 


MEMORY 




R 


REGISTERS 




S 


SAVE 




T 


TRANSFER 




V 


VERIFY 




X 


EXIT 

(period) 



Assemble a line of 6502 code 

Compare two sections of memory and report 
differences. 



Fill memory with the specified byte. 

Start execution at the specified address. 

Hunt through memory for all occurrences of 
certain bytes. 

Load a file from tape or disk. 

Display the hexadecimal values of Memory 
locations. 

Display the 6502 Registers. 

Save to tape or disk. 

Transfer code from one section of memory 
to another. 

Compare memory with tape or disk. 

Exit TEDMON. 

Assembles a line of 6502 code 
> (greater than) Modifies memory 
; (semi-colon) Modifies 6502 Register displays 

Location $7FB controls whether TEDMON looks at ROM or RAM above 
$8000, If this location is set to 0, TEDMON displays BASIC and the 
KERNAL when commanded to do a disassembly or memory dump 



184 



above $8000. If this location is set to $80 TEDMON displays the RAM 
under BASIC and the KERNAL. This is often convenient for machine 
language program development. Note that location S7F8 does not 
affect the GO command. The GO command starts execution in the 
current memory map (ROM on or RAM on) regardless of the setting 
of location $7F8, 

Using ^nter TEDMON by typing: 

Tedmon monitor 

TEDMON responds by displaying the 6502 registers and flashing the 
cursor. The cursor is your prompt that lets you know that TEDMON is 
v^aitJng for your commands. 



Command command: a 

Descriptions purpose: Enter a llne of assembly code. Ui 

SYNTAX: A <address> <opcode mnemonic> <operand> 

<address> A hexadecimal number indicating the location in memory 
to place the opcode, 

<opcode mnemonio A standard MOS technology assembly lan- 
guage mnemonic, e.g. LDA. STX, ROR, etc. '^ 

<operand> The operand, when required, can be of any of the legal 
addressing modes. (For zero-page modes a 2 digit hex number is re- _^ 
quired whose value is less than $100. For non-zero page addresses 
4 digit hex numbers are required.) 

A RETURN is used to indicate the end of the assembly line. If there 
are any errors on the line, a question mark is displayed to indicate an 
error, and the cursor moves to the next line. The screen editor can be 
used to correct any errors on the line. 

After a line of code is successfully assembled, the assembler prints a 
prompt containing the next legal memory location for an instruction, so 
A and the line number do not have to be typed more than once when — ' 
typing assembly language programs into the Plus/4. 



185, 



EXAMPLE: 

~~ .A 1200 LDX #$00 

.A 1202 

n 

NOTE A period (,) is equal to the ASSEMBLE command, 

EXAMPLE: 

. 2000 LDA #$23 

n COMMAND: C 

_ PURPOSE: Compare two areas of memory 

SYNTAX: C <adaress 7 > oddress 2> <address3> 

~" <Address 7 > is a hexadecimal number indicating the start address of 

the area of memory to compare against. 

\i <Address 2> is a hexadecimal number indicating the end address of 

the area of memory to compare against. 

<Address 3> is a hexadecimal number indicating the start address of 
the other area of memory to compare with. 

If the two areas of memory are the same, then TEDMON prints a 
RETURN, indicating that the second area of memory is the same 
rJ as the first. The addresses of any bytes in the two areas which are 

different are printed o-jt on the screen 



n 



COMMAND: D 

PURPOSE: Disassemble machine code into assembly language 
mnemonics and operands. 



n SYNTAX, D[<aadress>] [<address2>\ 



<address > A hexadecimal number setting the address to start 
the disassembly, 

oddress 2> An optional hexadecimal ending address of code 
to be disassembled. 

The format of the disassembly is only slightly different than the input 
format of an assembly. The difference is that the first character of a 



186 



disassembly is a period rather than an A (for readability), and the !_J 
Hexadecimal of the code is listed as well. 

A disassembly listing can be modified using the screen editor Make , 

any changes to the mnemonic or operand on the screen, then hit a ~~* 
carriage return, This enters the line and call the assembler tor further 

modifications. — i 

A disassembly can be paged. Typing a D causes the nexl page of dis- 
assembly to scroll onto the screen. — ^ 



EXAMPLE D 



3000 


3004 




3000 


A900 


LDA #S00 


3002 


FF 


??? 


3003 


DO 2B 


BNE $3030 



fll 



COf^^MAND; F (FILL) 

PURPOSE: Fill a range of locations with a specified byte. 

SYNTAX: F oddress 1> <address2> <byte> 

oddress 1 ~-- The first location to fill with the <byte> 

oddress 2> The last location to fill with (he <byte> 

<byte value> A 1 or 2 digit hexadecimal number to be written 

This command is useful for initializing data structures or any other 
RAM area. 



lJ 



EXAMPLE F 0400 0518 EA 

Fills memory locations from S0400 to $0518 with SEA (a NOP 
instruction.) 

COMMAND: G 

PURPOSE: Begin execution of a program al a specified address. 

SYNTAX: G I <address>) 

<address'^' An optional argument specifying the new value of the 
program counter and address where execution is to start. When 
<address> is left out, execution begins at the current PC. (The 
current PC can be viewed using the R command) 

The GO command restores all registers (dtsplayable by the R com- 
mand) and begins execution at the specified starting address. Caution ■ 

187 ■ 



is recommended in using the GO command. To return to TEDMON 
after executing a macinine language program, use the BRK instruction. 

EXAMPLE: G140C 

Execution begins at location S140C. 

COMMAND: H (HUNT) 

PtJRPOSE: Hunt throughi memory within a specified range for all 
occurrences of a set of bytes. 

SYNTAX: H oddress 1 > <address 2> <data> 

oddress 7 > beginning address of tiunt procedure 

oddress 2> ending address of hiunt procedure 

<da!a > data set to search for data may be hexadecimal or an 

ASCII stnng. An ASCII is specified by preceding the first character with 
a single quote, eg, 'STRING. Data may be single or multiple element 
argument. When multiple and in hexadecimal each number must be 
separated by a space. 



EXAMPLE. H COOO FFFF 'REAC 



HAOOOAlOl AgFF4C 




Search for 
ASCII string 
READing from 
COOO to FFFF 



Search for data $A9, 
Sff. S4C, fromAlOO 
toAIOI 



COMMAND: L (LOAD) 

PURPOSE: Load a file from cassette or disk. 

SYNTAX: L <"filename">. <device> 

<filename~- is any legal Plus/4 filename inside quotes. 

<devlce> is a hexadecimal number indicating the device to load from. 

1 is cassette 



188 



8 is disk {org, A, etc) 

The Load command causes a file to be loaded into memory. The start- 
ing address is contained in the first two bytes of tfie file (a program file). 
In other words, the LOAD command always loads a file into the same 
place it was saved from. This is very important in machine language 
work, since few programs are completely relocatable. The file is 
loaded into memory until the end of file (EOF) is found. 

EXAMPLE: L "SCREEN", 1 

reads a file from 
cassette. 



L "TANK", 8 

reads a file from disk. 

COMMAND: M {MEMORY DISPLAY) 

PURPOSE: To display memory as a hexadecimal and ASCII dump 
within the specified address range. 

SYNTAX: M [oddress 1 >] [<acfdress>] 

t<adcfress 7>] First address of memory dump. Optional If omitted, 
one page is displayed. The first byte is the last address specified. 

[oddress 2>] Last address of memory dump. Optional. If omitted, 
one page is displayed. The first byte is the dataof l<add/'ess ?>J. 

Memory is displayed in the following format: 

>A04841 E7 00 AAAA00 98 56 45 :A!.'..VE 

Memory content may be edited using the screen editor. Move the cur- 
sor to the data to be modified and type the desired correction and hit 
return. If there is a bad RAM location or an attempt to modify ROM has 
occurred, an error flag {?) is displayed. 

An ASCII dump of the data is displayed in REVERSE (to contrast the 
dump with other data displayed on the screen) to the right of the hex 
data. When a character is not printable, it is displayed as a reversed 
period (-). 



-J 



189 -- 



As with the Disassembly command, you can page down by typing M 
and RETURN. 



T i 



ii 



n 



EXAMPLE 






















MICOO 
























>1C00 


41 


E7 


00 


AA 


AA 


00 


98 


56 


45 


A!.', 


.VE 


>1C08 


41 


E7 


00 


AA 


AA 


00 


98 


56 


45 


A!.-. 


-VE 


>1C10 


41 


E7 


00 


AA 


AA 


00 


98 


56 


45 


A!.-. 


• VE 


>1C18 


41 


E7 


00 


AA 


AA 


00 


98 


56 


45 


A!.'. 


-VE 


>1C20 


41 


E7 


00 


AA 


AA 


00 


98 


56 


45 


Al.-. 


-VE 


>1C28 


41 


E7 


00 


AA 


AA 


00 


98 


56 


45 


A!.*. 


.VE 


>1C30 


41 


E7 


00 


AA 


AA 


00 


98 


56 


45 


A!.*. 


.VE 


>ic3a 


41 


E7 


00 


AA 


AA 


00 


98 


56 


45 


A!.*. 


.VE 


>1C40 


41 


E7 


00 


AA 


AA 


00 


98 


56 


45 


A!.*. 


.VE 


>1C48 


41 


E7 


00 


AA 


AA 


00 


98 


56 


45 


A!.*. 


.VE 


>1C50 


41 


E7 


00 


AA 


AA 


00 


98 


56 


45 


A!,*. 


.VE 


>ic5a 


41 


E7 


00 


AA 


AA 


00 


98 


56 


45 


A!.*. 


.VE 



COMMAND > (GREATER THAN sign) 

PURPOSE: Can be used to set 1 to 8 memory locations at a time. 

SYNTAX: > address data byte 1 <data byte 2...8> 

address: First memory' address to set 

data byte 1: Data to be put at address 

<data byte 2 to data byte 8> Data to be placed in the successive 

memory locations following the first address. Optional 



EXAMPLE 
>2000 08 



places an 08 at 
location 2000 



n 



>3000 23 45 65 



places a 23 at 
location 30C0. a 
45 at 3001. and 
a 65 at 3002 



190 



COMMAND: R (REGISTER DISPLAY) 

PURPOSE Show important 6502 registers The program status regis- 
ter, the program counter, the accumulator, the X and Y index registers 
and the stack pointer are displayed. 

SYNTAX R 

EXAMPLE: R 

PC SR AC XR YR SP — 

; 1002 01 02 03 04 F6 

NOTE: : (semi-colon) can be used to modify register displays in 

the same fashion as > can be used to modify memory registers. ^j 



u 



COMMAND: S (SAVE) ; 

PURPOSE: Save the contents of memory onto tape or disk. 

SYNTAX: S<'7//ename">,<dewce>,<adc/ress 1>.<address2> _J 

<"filename"> Any legal Plus/4 filename. To save the data, the filename 
must be enclosed in double quotes. Single quotes cannot be used — J 

<c'ewce> Two possible devices are cassette and disk. To save on 

cassette, use device 1 : The device number of the Plus 4 disk drive is — ^ 
usually 8, However, this can be changed (for instance, when using 

more than one disk drive). See your Plus/4 DISK DRIVE MANUAL, _j 

<address 1 > Starting address of memory to be saved. 

oddress 2> Ending address of memory to be saved + 1. All data up ' 
to but not including the byte of data at this address is saved. , 

The file created by this command is a program file. The first two bytes 

contain the standing address oddress 1 > of the data. The file may 

be recalled using the L command , "^ 

EXAMPLE S "GAME", 8, 0400. OBFF M 

Saves memory from $0400 to SOBFF onto disk. M 



COMMAND: T (TRANSFER) 

PURPOSE: Transfer segments of memory from one memory 
area to another. 



n 



n 



n 



SYNTAX T oddress 1 > <address2> oddress 3> 

oddress 1 > Starting address of data to be moved 

oddress 2 '■ Ending address of data to be moved 

oddress 3> Starting address of new location (wtnerettie data will go) 

Data can be moved from low memory to higiT memory or vice-versa. 
Additional memory segments of any lengtfi can be moved forward or 
backward any number of bytes (i.e . stuffed). 

EXAMPLE T 1400 1600 1401 

Shifts data from S1400 up to and including S1600 one byte tiigtier 
in memory. 

COMMAND V (VERIFY) 

PURPOSE Verify a file on cassette or disk witti ffie memory contents. 

SYNTAX V <"filename" :>. <device> 

■ filename > is any legal Plus,/4 filename. 

■device ■ is a fiexidecimal number indicating wfiicli device the file is 
on, cassette is 1 or 01, disk is 8 or 08, 09, etc, 

Ttie Verify command compares a file to memory contents. The Plus/4 
responds VERIFYING, If an error is found, ttie word ERROR is added; 
if the file IS successfully verified, the fiashing cursor reappears. 



EXAMPLE V "WORKLOAD", 8 

COMMAND X(eXit) 

PURPOSE Exit to BASIC 

SYNTAX X 

When the X command is given, the machine stack pointer is set to the 
current stack pointer value (see the R command). If this ts modified in 
any way, after exiting to BASIC use the BASIC CLR commanc to reset 
the pointers 



192 



SECTION 6 The following chart lists all of the characters built into the Commodore 
character sets It shows which numbers should be POKEd into screen 
memory (locatioris 3072 to 4095) lo gel a desired character (RemerTi- 
ber to set color memory -2048 lo 3071 ) Also shown is which char- 
acter corresponds lo a number PEEKed from the screen 

Two character sets are available, but only one set at a time. This means 
thai you cannot have characters from one set on the screen at the 
same time you have characters from the other set displ ayed T he 
sets are switched by holding down the ■■■■ and MHi l^eys 
simultaneously 

From BASIC. PRINT CHRS(142) will switch to upper-case/graphics 
mode and PRINT CHRS(14) switches lo upper'lowercase mode 

Any number on the chart may also be displayed in REVERSE The 
reverse character code may be obtained by adding 128 to the 
values shown. 




Screen 

Display 

Codes 



U 

u 

u 
-J 

-J 






tJ 



193, 



. J 



SET1 


SET 2 


POKE 


SET1 


SET 2 


POKE 


SET1 SET 2 POKE 


(11 







T 


t 


20 


( 


40 


A 


a 


1 


U 


u 


21 


) 


41 


B 


b 


2 


V 


V 


22 


* 


42 


C 


c 


3 


W 


w 


23 


+ 


43 


D 


d 


4 


X 


X 


24 




44 


E 


e 


5 


Y 


y 


25 


- 


45 


F 


f 


6 


Z 


z 


26 




46 


G 


g 


7 


1 




27 


/ 


47 


H 

1 


h 

i 


8 
9 


E 

1 




28 
29 




1 


48 
49 


J 


j 


10 


r 




30 


2 


50 


K 


k 


11 


*- 




31 


3 


51 


L 


1 


12 


SPACE 




32 


4 


52 


M 


m 


13 


1 




33 


5 


53 


N 


n 


14 






34 


6 


54 








15 


# 




35 


7 


55 


P 


P 


16 


$ 




36 


3 


56 





q 


17 


% 




37 


9 


57 


R 


r 


18 


& 




38 




58 


S 


s 


19 






39 


■ 


59 



194 



SET1 


SET 2 


POKE 


SET1 


SET 2 


POKE 


SET1 SET 2 


POKE 


< 




60 


D 


T 


84 


a 


108 


= 




61 


M 


U 


85 


B 


109 


> 




62 


Kl 


V 


86 


m 


110 


■7 




63 


O 


w 


87 


a 


111 


B 




64 


a 


X 


88 


E 


112 


a 


A 


65 


□1 


Y 


89 


H 


113 


m 


B 


66 


ffl 


z 


90 


H 


114 


H 


C 


67 


ffl 




91 


a] 


115 


H 


D 


68 


i] 




92 


c 


116 


Q 


E 


69 


[D 




93 


E 


117 


P 


F 


70 





ei 


94 


a 


118 


D 


G 


71 


3 


^ 


95 


n 


119 


nt 


H 


72 


SPACE 




96 


n 


120 


a 


1 


73 


B 




97 


u 


121 


Q 


J 


74 


H 




98 


□ 


122 


□ 


K 


75 


n 




99 


E 


123 


□ 


L 


76 


u 




100 


a 


124 


N 


M 


77 


u 




101 


a 


125 





N 


78 


^ 




102 


H 


126 


n 





79 


u 




103 


H 


127 


□ 


P 


80 


u 




104 






m 


Q 


81 


B 


^ 


105 






a 


R 


82 


LI 




106 






H 


S 


83 


LH 




107 










Codes from 128-255 are reversed images of codes 0-127. 



LJ 



195.^ 



SEQJIOfll 7 This appendix shows you what characters will appear If you PRINT 
CHRS(X), for all possible values of X. It will also show the values ob- 
tained by typing PRINT ASC(' X"). where.X is any character you can 
type. This is useful in evaluating the character received in a GET 
statement, converting upper/lower-case, and printing character 
based commands (like switch to upper/lower-case) that could not 
be enclosed in quotes. 




ASCII 

and 

CHRS 

Codes 



: 1 



n 



L J 



PRINTS 



CHRS 



PRINTS 



CHRS PRINTS CHRS PRINTS CHRS 








t 


17 




34 


3 


51 




1 


?^ 


18 


# 


35 


4 


52 




2 


CLR 
HOME 


19 


S 


36 


5 


53 




3 


ntST 
DEL 


20 


% 


37 


6 


54 




4 




21 


& 


38 


7 


55 


WHT 


5 




22 




39 


8 


56 




6 




23 


( 


40 


9 


57 




7 




24 


) 


41 




58 


DISABLES 
SHIFT ^t 

ENABLES 
SHIFT Cf 


8 

9 

10 


ESCAPE 


25 
26 

27 


4 
+ 


42 
43 
44 


< 


59 
60 
61 




11 


RED 


28 


- 


45 


> 


62 




12 


— * 


29 




46 


7 


63 


RETURN 


13 


OBN 


30 


/ 


47 


@ 


64 


SWITCH TO 
LOWERCASE 


■ 1'' 


BLU 


31 





48 


A 


65 




15 


SPACE 


32 


1 


49 


B 


66 




16 


! 


33 


2 


50 


C 


67 



196 



PRINTS 


CHRS 


PRINTS 


CHRS 


PRINTS 


CHRS 


PRINTS 


CHRS 


D 


68 


S 


97 





126 


ffl 


155 


E 


69 


m 


98 


n 


127 


PUB 


156 


F 


70 


B 


99 




128 


-• 


157 


G 


71 


a 


100 


H 


129 


YEL 


158 


H 


72 


n 


101 


FLASH 

ON 


130 


CYM 


159 


1 


73 


B 


102 


FLASH 

OFF 


131 


SPACE 


160 


J 


74 


D 


103 




132 


E 


161 


K 


75 


n 


104 


f1 


133 


H 


162 


L 


76 


tJ 


105 


f3 


134 


n 


163 


M 


77 


□ 


106 


f5 


135 


a 


164 


N 


78 


s 


107 


f7 


136 





165 





79 


□ 


108 


t2 


137 


m 


166 


P 


80 


N 


109 


t4 


138 


□ 


167 


Q 


81 





110 


f6 


139 


s 


168 


R 


82 


n 


111 


HELP 


140 


B 


169 


S 


83 


n 


112 ■ 


SHIFT RETURN 1 4 1 


□ 


170 


T 


64 


H 


113 


SWITCH TO 
UPPER CASE 


-42 


[B 


171 


U 


85 


P 


114 




143 


a 


172 


V 


86 


V 


115 


ni.K 


144 


H 


173 


w 


87 


D 


116 


\ 


145 


a 


174 


X 


88 


Q 


117 


RVS 
OFF 


146 


u 


175 


Y 


89 


^ 


118 


CLF 

HOME 


147 


E 


176 


z 


90 





119 


INST 
DEL 


148 


R 


177 


I 


91 


H 


120 


Q 


149 


a 


178 


£ 


92 


3 


121 


^ 


150 


ffl 


179 


1 


93 


as 


122 


O 


151 


c 


180 


T 


94 


ffl 


123 


H 


152 


c 


181 


<- 


95 


g] 


124 


01 


153 


a 


182 


B 


96 


m 


125 


ffl 


154 


n 


183 


















197 



^ 







PRINTS 


CHns PRINTS 


CHRS 


PRINTS 


CHRS 


PRINTS 


CHRS 


n 
u 


184 □ 

185 B 


185 
187 


a 


188 
189 


H 


190 
191 


CODES 
CODES 
CODE 


192-223 

224-254 
255 


SAME AS 
SAME AS 
SAME AS 




96-127 

160-190 

126 





. i 



. i 



. i 



198 



SECTION 8 The following chart lists which memory locations control placing 

characters on Ihe screen, and the locations used to change individual 
character colors, as well as showing character color codes. 




SCREEN MEMORY MAP 



Screen 

And 

Color 

Memory 

Maps 





— 1 






r" 


" 




'~-~ 






~ 


T 


























1 iTT 


1 ! ■ 1 ■ 




































1 1 










?T52 




' 




















1 
























va? 




































■ ■ : 








































i ; . ■ J 


1 






































rM2 








































! 1 . : . , , 1 




ns? 












































1 


1 ; , ; ; 1 : ; 




CIK* 












1 1 


























1 






1 


MIJ 




























1 














".; r: ^ ■ ' ■ ' 


1 


M7? 




























■ 














^ 1 1 


151? 






; 
















- 










3552 


























3592 


t ! 






















, 




3632 
367? 






'■■ 




















1 1 , 














































' 






37-12 
































i i 










1 




' 


3?52 








































1 














1 : 




3792 






























































3B32 








































1 
























:!872 














































, 












3912 


















|! '■ 














) 










3952 


















!■ i 
















; : ! 1 1 1 1 ' ■ . 


3992 






























■ ■ 1 ; 


4032 






__, 






_ 


_ 


_, 




1 ll 1 1 M 


-1-- 


_ 




i", , ■■,:.; 



10 s 






199 



COLOR MEMORY MAP 



I i 



COLUMN 

20 



39 

2087 



'OiR 


r- 




■n 




r 




p 


— 


- 


^ 




~ 


~ 


~ 






1 


"^ 


^ 


































1 


pnRfl 
















































































S128 










































































! 




71RR 








































































! 1 


??nR 




■ 


































































' i 


ppjfl 














































i 


??BB 








































I 


?3?fl 


























1 










• i 


235B 
2408 
2448 
?4Rfl 


f 


1 


' 










1 i 
















1 




1 










1 


. : 
































■ 


































l._l.._ 


) 




. 1 . 
























2528 


1 ' 


. 


i i i ^ 






















' 




2568 






































2606 
























, , 














16AS 










































2683 


- 


- - 


1 ■ ' ' 














! , 


















2728 


1 


































2766 










































28C6 
2846 


































1 1 










' 


1 






























_ - 1 - . 1 










2S8c 




















II 




























] 










2928 






















































1 












2968 






















































1 I 


' 










300B 


_ 




_ 


L 


U 






u 


L 




__ 






























1 1 


1 1 








1 , 



•0 g 

£ 



n 



The actual values to change a character s color are: 



1 BLACK 

2 WHITE 
3RED 

4 CYAN 

5 PURPLE 

6 GREEN 

7 BLUE 

8 YELLOW 



9 ORANGE 

10 BROWN 

1 1 YELLOW-GREEN 
12PINK 

13 BLUE-GREEN 

14 LIGHT BLUE 

15 DARK BLUE 

16 LIGHT GREEN 



The luminance of the color is selected by multiplying the luminance 
value (0-7) by 16. and added to the number for the color. To make the 
character flash, increase the color value by 128, 



. i 



200 



SECTION 9 




PLUS/4 10 
Memory 
Register 
Map 



13 
M 
IS 
16 
U 
T8 
19 
20 
21 
22 
23 
24 
25 
26 
27 
26 
29 
30 
31 
62 
63 



SFFOO 
SFF01 
SFF02 
iFF03 
SFFO^! 
$FF05 
SFF06 
SFF07 
$FF08 
SFf09 
SFFOA 
SFFOB 
SFFOC 
SFFOD 
SFfOE 
SFFOF 
SFF10 
SFFIl 
SFF12 
SFF13 
SFFIJ 
SFF15 
SFFIC 
$FF1? 
IFF 16 
SFF19 
SFF1A 
$FFia 
SFFIC 
SFF10 
$FF1E 
SFFIF 
$FF3E 
$FF3F 



0B7 


DB6 


DB5 


DB4 


DB3 


DB2 


DBl 


DBO 






TIMER* 1 RELOA 


D VALUE, BITS0'7(LOW) 








TIMER » 


IRELOADVALUE BITS8-15(HIGH1 








TIMER* 


2 RELOAD VALUE BITS 0-7 (LOWl 




TIMER # 2 RELOAD VALUE. BITS 9- 15 (HIGH) 






TIMER * 


3REL0ADVALUE, BITS0-7|LOWl 




TIMER * 3 RELOAD VALUE, BITS 8- IS IHIGH) 


TEST 


ECM 


BMM 


BLANK 


«ROWS 


Y2 


Y1 


YO 


RVS OFF PAL' 


FREEZE 


MCM 


*COLS 


X2 


XI 


xu 








KEYBOARD LATCF 








IRQ 


I-T3 


MC 


I-T2 


I-T1 


LLP 


I.RAB 


NC 


NC 


EI-T3 


NC 


EI.T2 


EITl 


EILP 


El-RAS 


flC8 


RC7 


RC6 


RC5 


RCJ 


RC3 


RC2 


RC1 


RCO 


NC 


NC 


NC 


NC 


NC 


NC 


C9 


CURS 


CURT 


CUR6 


CURS 


CUR4 


CUR3 


CUH2 


CURl 


CURO 


SNDl 


7 SNDI 6 


SND1-5 


SNDI -4 


SNDl-3 


SNOl-2 


SNOl-1 


SNDlO 


SND2- 


7 SND2-6 


SND2S 


SND2-4 


SN02-3 


SND2.2 


SN02-1 


SN020 


NC 


NC 


NC 


NC 


NC 


NC 


SN02-S 


SND2-8 


SND-REL NOISE 


V2SEL 


Vl-SEL 


V0L3 


V0L2 


V0L1 


VOLO 


NC 


NC 


BMB2 


SMB1 


BMBO 


RBANK 


S1-9 


Si -8 


CBS 


CB4 


CB3 


C82 


CBt 


CBO 


SCLOCK 


STATUS 


W.i 


VM3 


VM2 


VMl 


VMO 


NC 


NC 


NC 


BKGDO NC 


LUM2 


LUMi 


LUMO 


C0L0R3 


C0L0R2 


COLOPl 


coloho 


BKGDl NC 


LUM2 


LUM1 


LUMO 


color:- 


COLORS 


COLOR 1 


COl ORO 


BKGD2 NC 


LLIM2 


LUMl 


LUMO 


COLOR! 


C0L0R2 


COLOR! 


COLOHll 


BKGD3 NC 


LUM2 


LUMI 


LUMO 


COLORS 


C0L0R2 


COLOPt 


COLORO 


BKDG4 NC 


LUM2 


LUMl 


LUMO 


COLOR; 


C0L0R2 


COLOFI 


coloro 


NC 


NC 


NC 


^C 


NC 


NC 


BRE9 


BRE8 


BRE7 


BRE6 


BRE5 


BRe4 


BRE3 


BRE2 


BRE1 


BREQ 


NC 


NC 


NC 


NC 


NC 


NC 


NC 


VLB 


VL7 


VL6 


VL5 


VL4 


VL.l 


VL2 


VL1 


vlo 


HB 


H7 


H6 


H5 


HJ 


H3 


H2 


HI 


NC 


BL3 


3L2 


,BL1 


BLO 


VSUB2 


VSUB1 


VSUBO 


ROM SELECT 


RAM SELECT 



^ 



i!01 — 



t J 



; J 



i J 



L i 



SFFFE-FFFF 


■; IRQ VECTOR 


SFFFC 


< RES VECTOR 


SFFFA 


iNMI VECTOR (NOT USED) 


SFF81-FFF5 


■sKERNAL JUMP TABLE 


SFF40-FF80 


< 


5FFO0.FF3F 


.--TED CHIP 


SFEOO-FEFF 


<DMA DISK SYSTEM 



SFDEO-FDEF -; 

SFDDO-FDDF <CARTRIDGE BANK PORT 

SFD10-FD1F <6529 PARALLEL PORT 

SFDOO-FDOF <ACIA 



SDBOO-FCFF < 

SD000-D7FF <CHARACTERROM 

SC:000-D7FF •-: MORE BASIC 

SSQOO-BFFF < BASIC 

S4000-FFFF 

S2000-3FFF 

SICOO-IFFF 

SI 803-1 BFF 



SIOOO- 
SOCOO-OFFF 
S0800-QBFF 
SOOOO-OTFF 



i RAM, ALSO START OF BASIC TEXT 

.. AREA WHEN HIRES GRAPHICS ARE USED 

■ BIT MAP SCREEN DATA 

<HIRES SCREEN VIDEO MATRIX 

■■: HIRES SCREEN ATTRIBUTE BYTES 

■. BASIC TEXT AREA ( BIT MAP OFF) 

■: TEXT VIDEO MATRIX (SCREEN MEMORY) 

.; TEXT ATTRIBUTE BYTES iCOLOR MEMORY] 

■ SYSTEM STORAGE 



ROM BANK HIGH (com) 



TED Chip ana l.'0 
space appear in 
all memory maps 



ROM banking roulines 
(appear irr all ROM maps) 



ROM SANK HIGH 



ROM BANK LOW 



: ] 



•NOTE In Ihe 64K RAM sysleni- RAM goes Ifom SOOOO-SFCFF, and IromSFFdO-SFFFF 



202 



SECTION 10 Functions that are not inirinsic to BASIC 3.5 may be calculated as 
follows: 




Deriving 

Mathematical 

Functions 



FUMCTION 


BASIC EQUfVALENT 


SECANT 


SEC(X)=1/C0S(X) 


COSECANT 


CSC(X) = 1/SIN(X) 


COTANGENT 


C0T(X) = 1/TAN(X) 


INVERSE SINE 


ARCSIN(X)=ATN(X/SOR{ X'X-I)) 


INVERSE COSINE 


ARCCOS(X)= -ATN(X.SQR 




( • X-X+1)) + m'2 


INVERSE SECANT 


ARCSeC(X) = ATN(X/SQR(X'X- 1 )) 


INVERSE COSECANT 


ARCCSC(X)=ATN(X'SOR(X*X- 1 )) 




+ (SGN(X)-1*T7/2) 


irsiVERSE COTANGENT 


ARC0T(X)=ATN(X)+-/2 


HYPERBOLIC SINE 


SINH(X) = (EXP(X)-EXP(-X))/2 


HYPERBOLIC COSINE 


C0SH(X)=(EXP(X)= + EXP(-X))'2 


HYPERBOLIC TANGENT 


TANH(X) = EXP(-X)/(EXP(x) + EXP 




(-X))-2+1 


HYPERBOLIC SECANT 


SECH(X) = 2'(EXP(X) + EXP( - X)) 


HYPERBOLIC COSECANT 


CSCH(X)=2,'(EXP(X)-EXP(-X)) 


HYPERBOLIC COTANGENT 


COTH(X)=EXP(-X)/(EXP(X) 




-EXP(--X))*2 + 1 


INVERSE HYPERBOLIC SINE 


ARCSINH(X) = L0G(X + SQR(X'X+1» 


INVERSE HYPERBOLIC COSINE 


ARCC03H(X) = L0G(X + SQR(X'X-1)) 


INVERSE HYPERBOLIC TANGENT 


ARCTANH(X) = LOG((1+X)/(1-X))/2 


INVERSE HYPERBOLIC SECANT 


ARCSECH(X) = LOG((SQR 




(-X'X + 1) + 1)/X) 


INVERSE HYPERBOLIC COSECANT 


ARCCSCH(X) = LOG((SGN(X)*SOR 




(x'x + 1)/x)) 


INVERSE HYPERBOLIC COTANGENT 


ARCCOTH(X) = LOG((X + 1 )/(x - 1 ))/2 



_J 



-I 

_l 
J 
ij 



203 — 



SECTION 11: mjE 




The above table conlains the sound register values of four octaves of 
notes. The sound register values are used as the second parameter 
of the SOUND command. To use the first note in Ihe table (A— sound 



204 



register value 7) use the 7 as the second number after the SOUt^D j 
command— SOUND 1,7,30. 

Use the following formula to find the sound register values for frequen- | 

cies other than those in the table: 

SOUND REGISTER VALUE = 1024— (111 860.781/FREQUENCY) _i 

Both the table of sound register values and the above formula are for 

NTSC televisions. This is the television standard used throughout the — > 
United States and all of Canada. If you are in a country where PAL is 

the television standard, you should use the following formula to calcu- \ 

late new sound register values for the entire table: 

SOUND REGISTER VALUE = 1024— (111840.45/FREQUENCY) _ 



205 -^ 



SECTION 12 




Programs 
TrJ 



I i 



5 GRAPHIC 3,1: GRAPHIC 0, 1 

10 INPUT "SHOULD I CLEAN UP MY MESS"; A$ 

20 INPUT "SHOULD I ROTATE"; B$ 

30 INPUT "SHOULD I VARY MOTION"; C$ 

40 INPUT "SHOULD I PICK THE START" ; D$ 

50 IF A$ = "Y" THEN DIM A (3,200) 

60 DEF FNA (X) = INT(RND(1) * X) 

70IFD$ = "Y" THENXl=FNA(80) + 80: X2=FNA(80) + 80: 

Y1=FNA(100) + 100 
75 IF D$ = "Y" THEN Y2 =FNA(100) + 100 
80IFD$<>"Y" THEN XI =80: X2 = 80: Yl =100: Y2 = 100 
90 GRAPHIC 3: FORL = l TO 3: COLOR L, FNA(15)-f2, FNA(8); 

NEXT 
100 IF CI '■-: 1 THEN COLOR FNA(3) + 1, FNA(15) +2, FNA(8) : 

Cl=FNA(40) + 20 
110IFC2<-^>OTHEN140: ELSEXA = FNA(ll)-5: XB=rNA(ll)-5: 

YA=FNA{13)-6 
115YB=FNA(13)-6 
120 IF CS = "Y" THEN C2=FNA(10) + 5 
130IFB$ = "Y"THENXB = -XA: YB = -YA 
140IFC3': 1THENC = FNA(3) + 1: C3 = FNA(10) 
145 IF A$ = "Y" THEN DRAW 0, A(0,P), A(1,P) TO A(2,P), A(3,P) 
150Xl=Xlt-XA: X2=X2+XB: Yl= Y1+ YA: Y2= Y2+ YB 
160IFX1<OORX1>159THENXA= -XA:X1=X1+XA 
170 IF X2<0 OR X2>159 THEN XB= -XB: X2= X2+XB 
180 IF YKO OR Yl >199 THEN YA= - YA: Yl = Yl +YA 
190IFY2<0ORY2>199THENYB= -YB: Y2= Y2 + YB 
200 DRAW C, XI, Yl TO X2, Y2 
210IFA$-"Y"THENA(0,P)=X1: A(1,P)=Y1: A(2,P)=X2; 

A(3,P)=Y2:P=P + 1 
215 IF A$ = "Y" THENIFP>200THENP = 
220 Cl= Cl-1: C2= C2-1: C3- C3-1: GOTO 100 



Sound 
Effects 



t J 



Wolf Whistle 

10VOL7 

20 FORL = 400TO800STEP20 

30SOUND1,L,3;NEXT 

40 FORL = 300TO600STEP40 

50SOUND1,L,3:NEXT 

60FORL = 600TO300STEP-40 

70SOUND1,L,3:NEXT 



206 



Computer Maniac 

10VOL7 

20FORL = lTO100 

30 SOUND1,INT(RND(0)*500)+400,4 

40 NEXT 



Telephone 

10VOL7 -^■ 

20FORL = lTO5 • 

30FORM = lTO60 

40 SOUNDl, 466,1 ■ 

50 SOUNDl, 1020,1 

60 NEXT Ig 

70FORZ = lTO2000:NEXT 

80 NEXT 

Busy Signal 

10VOL7 |M 

20FORL=lTO15 

40 SOUND1,466,20 ^ 

50SOUND1,1020,15 ■ 

80 NEXT 

Bubbles "" 

10 VOL? ^ 

20 GRAPHICl.l ■ 

30FORM=lTO50 

40 GOSUB80 ■ 

50 SOUNDl, gOO-R*20, (YR/2) + 50 

60 CIECLE1,X,Y,R,YR M 

7 NEXT : GRAPHIC ; E ND 

80X = INT(RND(0)*280)-20 ^ 

gOY = INT(RND(0)*160) + 20 • 

100R = INT(RND{0)*40) + 5 

110YR = R/1.3 jjl 

120 RETURN 

Zap Beam ^ 

10VOL7 

20FORM = lTO20 H 

30 FORL = 900TO850STEP - 10 

40 S0UND1,L,1 ii 



207 — ' 



50 NEXT 

60 FORL = 850TO90GSTEP10 

70SOUND1,L,1 

80 NEXT 

100 NEXT 



Music Lines 

10VOL7 

1BX1=0:Y1=0 

20 GRAPHICl.l 

30 GETA$ : IFA$ = ■ ■ "THENGRAPHICO : END 

40 GOSUB80 

45 FORL= 1TODSTEP2 

50SOUNDl,X-3,5 

55SOUND2,Y-3,5 

60 DRAWl.X.Y 

65X = X + 2-DX:Y = Y + 2"DY 

70NEXT:GOTO30 

80X = X1:X1=INT(RND(0)*280)^20 

90Y = Y1:Y1 = INT(RND(0)'160) + 20 

100A = X1 X:B=Y1-Y:D = SGH(A'A+B*B) 

110DX-=A,D:DY-B/D 

120 RETURN 



208 



SECTIOH 13 Introduction 




RS-232 

Interface 



Opening 

The 

RS-232 

Channel 



Your Commodore Plus/4 has a built in RS-232 interface for connection 
to any RS232 modem, printer, or olfier device. To connect a device to 
your Plus/4 requires a cable and some additional programming. The 
Commodore modem connects directly. 

RS-232 on the Plus/4 is standard RS-232 format, bat the voltages are 
TTL levels (0 to 5V) rather than the normal RS-232 -12 to 12 volt range. 
The cable between the Commodore Plus/4 and the RS-232 device 
should accommodate the necessary voltage conversions. (The Com- 
modore RS-232 interface cartridge handles this properly.) 

The RS-232 interface software can be accessed from BASIC or from 
the KERNAL for machine language programming. This section ad- 
dresses the use of RS-232 from BASIC. For more detailed information, 
and for use from machine language, consult the Commodore Plus/4 
Programmers Reference Guide. RS-232 from BASIC level uses the 
normal BASIC commands; OPEN, CLOSE, CMD, INPUT#, GET#. 
PRINT*, and the reserved variable ST INPUT* and GET# recall 
data from the receiving buffer, while PRINT* and CfvID place data into 
the transmitter. 

Only one RS-232 channel should be open at any time; a second OPEN 
statement causes the receive buffer pointer to be reset, causing any 
characters in the buffer to be lost. 

Up to 4 characters may be sent in the filename field. The first two are 
control and command register characters; the other two are reserved 
for future system options. Baud rate, parity, and other options can be 
selected through this feature. 

Basic Syntax: 

OPEN lf.2,0,<">control register command register<"> 



EXAMPLE; ^ 

OPEN 2,2,0, CHR${5) + CHRS(15) ■ 

//—Normal logical file id. (1-255). If If > 127, then linefeed follows __ 
carnage return. 

con/fo/reg;s(e/'— Single byte character (see Figure 1) (required to . 

specify baud rate) 

command register — Single byte character (see Figure 2) ■■ 



209 



Getting 

Data 

From 

An 

RS-232 

Channel 



When receiving data, the Commodore Plus/4 receiver buffer holds 127 
characters before the buffer overflows. This is indicated by the RS-232 
status word (ST from BASIC). All characters received when the buffer is 
full are lost. Obviously, it pays to keep the buffer as empty as possible. 

Receiving RS-232 data at high speeds calls for use of machine lan- 
guage, since the speed of BASIC is a iimitation. 



CONTROL REGISTER 



CONTFIOL REGISTER 

The Comto'' Regsler is used :□ select [he desiTsd mode (or 
ihB 6551 The word length, number ot slop Oils, and clocK 
conlfols are all clesefmined by ]he Control Register, which is 
depicied in Figure l 



' 1 s^op Bs 

1 = 2 aop B.1S 

1 S:op Br: If Ward Length 
= 5 315 anr! PstAy' 
tvi Srap Bils il W:rd Ungtn 
° 5 Bils ana r^Q Parry 



V»'ORD LENGTH ■ 



BT 


□ATAWOfID 


6 


5 


LENGTH 





C 


& 


a 


T 


7 


1 


t 







1 


5 



RECELVEfl CLOCK SOURCE " 



= E«;e'nai flecaivef CiKk 
= Baud fia!e Geneif^tor 



s foi- S-DhI UEPsniission (B oaia Djcs pMs panty) 



baud rate 
generatofj 



l6KE;<TEFlNALCLaCK 



36C0 



1-ARDWAPlE RESET 
PROGRAM RESET 



D'OOOOOOC 



Figure 1. Control Register Format 



. J 



Basic Syntax: 

Recommended: GET# If, <string variable> 
NOT Recommended: INPUT* It, <vanable list> 



210 



COMhIAND REGISTER 

The Comrriand RegssteT is used to conlrot Specilic 
Transm<i;Receive functions and is shown (n FiQuia 2 



COMMAND REGISTER 



PARITY CHECK COWTPOLS - 






BIT 


OPERATION 


7 


6 


b 




- 







Party OaatMC-UCPh'ty &l 
GttTWfBled— No Paiily &1 RcceviJO 





D 


1 


OOd PvDy Receive' and Tian^m.tie' 





' 


1 


Ehwi Par*y Ftec&vef afi3 
TrBn«m*lor 


5 
1 





5 


Mark Paslty Bt TrarTsmfiea 




1 


Space Pjirty aj Trans-Trtied 
Pani'/Checi.&SaHlea 



NORMALECMO MODE 
FOflftECErvEn 



O-hiorrrui 
1 =Echo(B«ls2arKl3 
mifii be "0 1 



ERMlNALREAD^ 



- DitaDki Hwcwvei flfid All 
^nl**tuOI*lOTRr^^gtll 

hM.(Kru(H»(OTR**| 



PECeiVEH iNTER'^UPr ENAHLE ^^ 

-TRANS»JH-TER COVTROLS 



qI Siiiui flegaie* 
1 - inOlnieenxMChMMO 



0,1 1 


T PA NSW IT 
iNTEWRUPf 


ms 

LEVEL 


IRANSMhTTER 


3 


? 


a 





D>vAC>«d 


h^t. 


OtI 





1 


EnjiOM 


lt>* 


On 


1 





DisatJcd 


LOW 


On 


1 


1 


D^^aU«C 


Low 


Tfansr^ 8FK 



HAROWARE RESET 
PROSflAW RESET 



7 6 5 4 3: 10 

OOOODOOO 

■ -00000 



* Thi«B Ms rvjU be set to Hifl g rvei^ ifi^-yts 



Ftgun 1. Command R*glil«r Fonrntl 



NOTES 



If the word length is less than 8 bits, all unused bit(s) are assigned a 
value of zero. 

If a GET# does not find any data in the buffer, the character "" (a null) 
is returned. 

If INPUT* is used, ttien the system hangs until a non-null character 
and a following carriage return (s received. Thus, if the CTS or DSR 
line(s) disappear during character INPUT#, the system hangs in a 
RESET-oniy state. This is why the INPUT# and CHAIN routines are 
NOT recommended. 



211 



Sending Data Basic syntax: 

To An RS-232 CMD //—acts same as tn BASIC specifications 

Channel PRINT# !f.<vanable!ist> 

ClOSinfl Closing an RS-232 fiie discards all data in the t)uffer at ttie time of 

Ap execution, stops all RS-232 transmitting and receiving, and sets the 

nq nnn RTS and Sout lines high. 

Data Basic Syntax: 

Channel close// 



Tablet 


RS-232 Port Lines 








PIN 










ID 


DESCRIPTION 


EIA 


ABV 


OUT 


C 


RECEIVED DATA 


(BB) 


Stn 


IN 


D 


REQUEST TO SEND 


(CA) 


RTS 


OUT 


E 


DATA TERfvllNAL READY 


(CD) 


DTR 


OUT 


F 


RING INDICATOR 


(CE) 


Rl 


IN 


H 


RECEIVED LINE SIGNAL 


(CF) 


DCO 


IN 


J 


UNASSIGNED 


{ ) 


XXX 


IN 


K 


CLEAR TO SEND 


(CB) 


CTS 


IN 


L 


DATA SET READY 


(CC) 


DSR 


IN 


8 


RECEIVED DATA 


(BB) 


Sin 


IN 


M 


TRANSMITTED DATA 


(BA) 


Sout 


OUT 


A 


PROTECTIVE GROUND 


(AA) 


GND 




N 


SIGNAL GROUND 


(AB) 


GND 





212 



MODES 

171 161 151 Ml 



2 I 



1 I I I (Machine lang —rssiai) 

;. PARITY ERROR BIT 

;, FRAMING ERROR BIT 

RECEIVER BUFFER OVERRUN BIT 

UNUSED BIT 

CTS SIGNAL MISSING BIT 

UNUSED BIT 

DSR SIGNAL MISSING BIT 

BREAK DETECTED BIT 



Figure A-3 RS-232 Status Register 

NOTES 

If theBIT=0, then no error has been detected. 

The RS-232 status register can be read from BASIC using tine variable 
ST 

If ST is read by BASIC or by using the KERNAL READST routine the 
RS-232 Status word is cleared upon exit. If multiple uses of the STATUS 
word are necessary, tfie ST should be assigned to another variable, i.e. 

SR=ST: REM ASSIGNS ST TO SR 

The RS-232 status is read (arid cleared} only when the RS-232 channel 
was the last external i/0 used. 



213 



SAMPLE 

BASIC 

PROGRAM 



I 1 



This program opens the telecommunications channel to allow you to 
communicate using a modem. 

100 OPEN 5, 2, 2, CHR$(22) + CHR$(6): REM ALLOCATE BUFFER 

AND OPEN CHANNEL 
110DIMF%(255), T%(255) 
120 FOR J= 32 TO 64: T%(J)-J:NEXT 
130T%(13) = 13:T%[20) = 8:RV=18: CT=0 
220FORJ = 65TO90: K=J + 32: T%(J)=K:NEXT 
230FORJ = 91TO95: T%(J)=J:NEXT 
240 FOR J= 193 TO 218: K=J-128: T%(J)=K: NEXT 
250 T%(146) = 16: T%{133) = 16 
255 T%(137)=3: T%(134) = 17: T%(138) = 19 
260 FOR J=0 TO 255 
270K=T%(J) 

280 IF KOO THEN F%(K)=J: F%(K + 128)=J 
290 NEXT 

300 PRINT" "CHRS(147) 
310GET#5,A$ 
320 IF A$ = "" THEN 360 

330 PRINT" "CHR$(157);CHR$(F%(ASC(A$))): 
340 IF F%(ASC(A$)) = 34 THEN PRINT CHR$(27)"0"; 
350 GOTO 310 

360 PRINT CHR$(RV)" "CHR$(157);CHR$(146);; GETA$ 
370IFA$<>""THENPRINT#5,CHR${T%(ASC(A$))); 
380CT = CT+1 

390IFCT = 8THENCT = 0:RV = 164-RV 
410 GOTO 310 



214 



SECTION 14 The following lists include a sampling of the computer and program- 
ming books available. Thie title of the book is listed first, followed by thie 
author and publisher. 

Commodore Books 

VIC 20 Programmers Reference Guide 
Commodore 64 Programmer's Reference Guide 
Commodore Plus/4 Programmer's Reference Guide 
fvlastering YourVIC20 
Four ViC 20 Computer Books: 

VIC Revealed. Nick Hampshire 

VIC Games, Nick Hampshire 

VIC Graphics, Nick Hampshire 

Stimulating Simulations for the VIC, C.W Engel 
Introduction to BASIC, Part 1 and 2, Andrew Colin 
Commodore Software Encyclopedia, Third Edition 




Books 

For 

CDmmodore 

Products 



BASIC Programming 

Arnnchair BASIC: An Absolute Beginner's Guide to Programming 

in BASIC, Fox & Fox. Osborne/McGraw-Hill 
BASIC Handbook. Second Edition, Lien, Compusoft 
Basic Commodore 64 BASIC, Coan. Hayden 
Elementary BASIC, Ledgard & Singer, SRA 
How to Build a Program, Emmerichs. Dilithium Press 
Instant Freeze-Dried Comiputer Programming in BASIC, Brown 
My Computer Lil<es Me When I Speak in BASIC, Aibrecht, 

Dilithium Press 
Nailing Jelly to a Tree, Willis & Danley, Dilithium Press 
The Programmer's Book of Rules, Ledin & Ledin, Lifetime 

Learning Publishers 
Technical BASIC. Kassab, Prentice-Hall 

Machine Language Programming 

Machine Language for Beginners. Mansfield, COMPUTE! Books 

Programming the 6502, Zaks. Sybex 

6502 Assembly Language Programming, Leventhal, Osborne/ 

McGraw-Hili 
6502 fylicro Chart, Micro Logic Corp. 
6502 Software Design, Scanlon, Sams 
The 6502 Software Gourmet Guide & Cookbook, Findlay, Hayden 



215 — 



. i 



. J 



Abbreviations for BASIC 

statements 169-171 
Animation 87-89 
Arrays 164 
ASCII and CHRS codes 169, 

196-198 
Assigning data 

DATA . ^ . READ statements 
74-75. 133-134, 151, 170 

INPUT 73. 141. 170 

GET 138. 169 

LET 142, 170 
AUTOmatic renumbering 118. 169 

B 

BACKUP command 118. 169 

BASIC 
abbreviations 169-171 
commands 69-82. 118-129 
converting to Commodore 

BASIC 172. 173 
functions 28-31, 158-163 
statements 69-82. 130-157 

BOX statement 100-101, 130. 
169 

Built-in software 34 



Calcuialions 
addition 59. 63 
decimals 59 
division 59, 63 
execution order 62-63 
exponentiation 65 
fractions 59 
mathematical operators 59. 

167-168 
multiplication 59. 63 
parentfieses 62-63 



PRINT statement 61-62 

relational operators 59. 
167-168 

scientific notation 60 

subtraction 59. 63 
Cartndges 

installing 35 

loading 35 
Cassette tapes 

recorder 4. 19 

LOADing 36 

SAVEing 37. 127 

software 36-37 
■CHAR statement 95-96. 130-131, 

169 
CHRS codes 169, 196-198 
CHRS function 162, 196-198 
Clearing 25-26 
CLR command 25-26, 132, 169 

graptiics modes 28, 84-89 

graphics screen 93, 169 

memory 199-202 

screen 193-195 
CIRCLE statement 98-100, 

131-132, 169 
CLOSE statement 132, 169 
CLR statement 25-26, 132. 169 
CfvID statement 132-133. 169 
COLLECT command 119. 169 
Color 

areas 90-91 

background 90-91 

border 90-91 

changing 27. 100-101 

COLOR statement 90-91. 133, 
169 

filling areas 100-101 

keys 27 

luminance 90 

memory map 199-202 

PAINT 100-101, 145 

screen 193-195 



216 



Commands (See BASIC 

commands) 
Commas 

in PRINT statements 55-56 

separating numbers 61 

vs. semicolons 55-56 
Commodore key 26 
Conditional Statements 

IF/THEN 79, 140-141. 170 
Connecting ttie computer 8-18 
CONT command 119. 169 
Control (CTRL) key 26 
Control Statements 

GOTO 47, 76-77, 139 

FOR/NEXT/STEP 77-78 
Conversion programs 172-173 
COPY command 119, 169 
Copying diskettes 119 
Cursor 

controlling movement 25-26 

cursor keys 25-26 

in PRINT statements 25, 49-51 



DATA statements 74-75, 133-134 
Debugging 

CONT 119, 169 

DS$41 

STOP 155. 171 

RESUME 152. 171 

TRAP 155, 171 
DEF FN statement 134, 169 
Defining functions keys 30-31 
Defining functions in programs 

30-31 
DELete 

command 25. 120. 169 

editing 25 

files from a diskette 25 

key 25 

letters in a word 25, 49-51 



lines in a program 25. 49-51 , 
120 
DIfVI statement 134-135, 169 
Dimensioning an array 134-135 
Direct mode 70 
DIRECTORY 41, 120-121, 169 
Diskettes 

COPY statement 119. 169 

DIRECTORY command 41 , 
120-121, 169 „ 

disk drives 4. 19, 38 

disk errormessages 39, 174- 
183 

DLOAD command 30-31, 
38-39, 121. 169 

DSS41 

duplicating 119 

formatting 39-40 

HEADER command 39-40, 
122.170 

listing a directory 41. 120-121 

loading 38-39. 121, 124-125 

SAVEing 40-41, 127 

table of contents 41 
DLOAD 30-31, 121 
DO/LOOP/WHILE/UNTIL'EXIT 

78. 135-136 
DRAW 94-95, 136, 169 
DS$41 

DSAVE 30-31, 122, 169 
Duplicating diskettes 119 



Editing 
INSertkey25 
INSert mode 25, 28-29 
DELete key 25 
DELete command 25. 120, 

169 
RENUMBER command 70. 
126-127, 171 



U 



217. 



: J 



. 1 



Encyclopedia 115-214 

END statement 136 

Errors 
Debugging statements 

174-183 
Disl< errors 39, 174-183 
Messages explained 39, 
174-183 

ESCape functions 28-29, 57 

ESCape key 28-29 

EXP function 158, 169 



Flash mode 

Flash on and off 27 

keys 27 

using tn PRINT statements 27 
FOR... TO... STEP 77^78, 

136-137 
Formatting diskettes 39-40 
Formatting output 

PRINT USING 145-150 

PUDEF 150-151, 170 

print zones 55-56 

punctuation 55-56 
Functions 

Numeric 59-67, 158-162, 203 

String 162-163 

Other 163 
Function keys 30-31 



GET statement 138, 169 

GETKEY statement 74, 138, 169 

GET# 138-139, 169 

GOSUB80. 139. 169 

GOTO 47. 76-77, 139, 169 

Graphics 
BOX 97-98, 100-101, 130,169 
CIRCLE 98-100, 131-132, 169 
clearing 93, 169 



COLOR 90-91, 169 
DRAW94-95, 136, 169 
GRAPHIC command 92-93, 

139-140, 157, 169 
tiigh resolution 92-93 
keys 28-29 
modes 28, 84-89 
multicolor modes 102-103 
PAINT 100-101, 145 
printing graphic symbols 

84-86 
uppercase/graphic mode 24, 

28 
GSHAPE 153-154, 170 

H 

HEADER command 39-40, 122, 

170 
HELP key 30-32, 123 
High resolution graphics 92-93 

I 

IF.., THEN... ELSE 79, 140-141, 

170 
Immediate mode 62, 70 
INPUT* 141,170 
INPUT statement 73, 141, 170 
Input/Output Statements 

PRINT 71-73 

INPUT 73, 141. 170 

GETKEY 74, 138, 169 

READ/DATA 74-75, 133-134, 
151, 170 
Insert 

editing 25 

key 25 

mode 25 
Insert mode 

accessing 25, 28-29 

key 25 
Installing the computer 8-18 



218 



INSTR function 158-159, 170 
INT function 66-67, 159, 170 
Integer variables 64, 164 



Joy sticks 5, 12, 159, 170 



Key command 31, 123, 170 
Key redefining 30-31 
Keyboard 

color keys 27 

cursor keys 25-26 

graphic keys 28-31 

help key 30-32 

programmable function keys 
30-31 

special keys 24, 29 



Lefts function 162, 170 
LET statement 142, 170 
LIST statement 30-31 , 48-49, 

124, 170 
Loading 

cartridges 35 

cassettes 36 

diskettes 38-39, 121 

DLOAD command 30-31 , 

38-39. 121.169 
LOAD command 124-125, 170 
LOCATE 

statement 142, 170 

Loops 

DO. . . LOOP. - . WHILE'UNTfL 
78, 135-136 

GOSUB80. 139 

GOTO 47, 76-77, 139 

FOR... TO... STEP 77-78, 
136-137 



IF... THEN... ELSE 79, 

140-141,170 — 

ON...GOSUB/GOT0 143, 

170 ^ 

Luminance 90 

M - 

Macliine Language fyionifor 

184-192 _ 
Mathematical functions 59-67, 

158-162.203 — 

Mathematical operators 59 

IVlemory maps 199-202 , 

MIDS function IB'', 170 

rvlodems2l4 

r\/lodes 

flash 27 

graphics 84-89 ■ — 

insert 28-29 

multi-color 102-103 ^ 

reverse 45-46 

uppercase/graphic 28, 84-86 

upper/lowercase mode 28, — 

84-86 

MONITOR 142, 170 

Monitor 

connecting to compuler 13-16 

machine language 184-192 
(Vlulti-Color graphics 102-103 
Music — ' 

duration of notes 107 

SOUND statement 106. 

204-205 

voices 106-107 

volume 105, 156, 171 — 

N - 

NEW command 51, 126. 170 
NEXT slatement 77-78, 143. 170 — 
Numbers 
calculating 61-67, 72-73, 203 



219 



exponentiation 65 
execution order in multiple 

calculations 62-63, 65-67 
fractions 59-60 
nnattier^atical operators 59 
pi 59. 163 
relational operators 59, 

167-168 
scientific notation 60 
signs (+ and -)59 
variables 64, 170 



0N,..G0SUB143, 170 
ON... GOTO 143 
OPEN command 144-145, 170 
Operators 59, 167-168 



PAINT 100-101, 145, 170 

PEEK function 160. 170 

Peripherals 19-21 

Pi 59, 163 

Pixel cursor 
in graphics modes 84-89 
LOCATE statement 142, 170 
positioning 25-26. 49-51 

POKE statement 146. 170 

Power supply 8, 12-13, 16-17 

PRINT 
calculations 61-62, 72-73. 203 
displaying messages 71-73 
formatting output 145-150 
in immediate mode 62, 70 
in program mode 71-73 
print zones 55-56 
punctuation 55-56 

PRINT# 147, 170 

PRINT USING 145-150, 170 

Print zones 55-56 



Program flow control (See 

Loops) 
Programming 
BASIC commands 69-82, 

118-129 
BASIC functions 30-31, 

158-163 
BASIC statements 69-82. 

130-157 
function keys 28-31, 123 
machine language monitor 

184-192 
mode 70 
PUDEF 150-151. 170 



Quote mode 
accessing 47, 56 
keys 47 

using in PRINT statements 
47-48,56 



Random numbers 65-67, 171 
READ statement 74-75. 151 , 170 
Relational operators 59, 167-168 
REIVI statement 80-81 , 151-152, 

170 
RENAfvIE command 126. 171 
RENUMBERING program lines 

70. 126-127 
Reset button 10 
RESTORE 152. 171 
RESUME 152. 171 
Resuming program display 152, 

171 
RETURN 152, 171 
Reverse mode 

accessing 27, 45-46 

kevs 27. 45 



220 



using in PRINT statements 
45-46 
RF cable 9, 11 
RIGHTS function 163, 171 
RND function 66-67, 160-161 , 

171 
RS-232 Interface 209-213 
RS-232port 12 
RUN command 30-31 , 70, 127, 

171 



SAVE command 127-128, 171 
Saving programs 

cassettes 37 

disk errors 41, 174-183 

diskettes 40-41, 127-128 

DSAVE 30-31, 40, 127 

SAVE 127-128, 171 
SCALE 152-153, 171 
Scientific Notation 60 
SCNCLR statement 93, 153, 171 
SCRATCH command 128, 171 
Screen 

clearing 25-26. 132, 169 

clearing graphic modes 93. 
169 

display codes 26, 52, 193-195 

LIST command 30-31, 48-49, 
170 

memory map 199-202 

program display 193-195 

resuming display 152 

size 57, 86 

slowing display 26 

windowing 57 
Screen area numbers chart 90 
Semicolons 

in PRINT statements 55-56 

vs. commas 55-56 
Setting up the computer 8- 18 



Slowing program display 26 
Software 

built-in 34 

cartridges 35 

cassettes 36-37 

diskettes 38-41 

LOADing 35-36. 38-40 

saving your own 37, 40-41 , 
127-128 
Sound effects 108. 206-208 
SOUND statement 106, 153, 

171,204-205 
SPC function 163, 171 
SSHAPE 153-154. 171 
STOP statement 155, 171 
Stopping program display 24, 

52 
String functions 162-163, 171 
Subroutines 80 
SYS statement 34. 155. 171 



TAB function 88, 163, 171 
TEDMON 184-192 
TEXT 

in graphics 92-93 

in PRINT statements 71 -73 

string functions 70-73, 
162-163 
TIS function 164, 171 
TRAP statement 155, 171 
TROFF156, 171 
TRON 155, 171 
Troubleshooting chart 17-18 
TV 

antenna types 13, 17 

channel selection 11,15-17 

hookup 13-18 

switch box 9, 11. 13. 15-17 



221. 



u 

uppercase/graphics modes 
accessing 24. 26, 28 
printing graphics 84-89 
SHIFT key 24. 28 

Upper, lowercase graphics 
accessing 24. 26, 28 
printing graphics 84-89 
SHIFT key 24, 28 



Variables 

floating point 64, 164 

integer 64, 164 

reserved names 116-117, 
165-166 

textstnng64, 73, 164 

types 64, 164-166 

see also Assigning data 
VERIFY command 70, 128-129, 

171. 192 
Voices 106-107 
volume 105, 156, 171 

w 

WAIT statement 156, 171 
Windowing 57, 86 



222 



d 
y 



223 — ^^ 



n 



n 



a 



n 



^z- 



n 

IV' 

n 

r 

n 



About the Commodore PLUS/4 ™ User's Manual . . . 

The Commodore Plus/4, the "productivity machine," is perfect 
for finances, accounting or any small business application. As 
a home computer, the Commodore Plus/4 has 64K of memory, 
with advanced color, graphic, sound and BASIC programming 
capabilities. This easy-to-read User's Manual gives you all the 
information you need to set up your equipment, use software 
and learn about computing with your new Commodore Plus/4. 

Even if you've never used a computer before, you can follow 
the step-by-step instructions and explanations to get into com- 
puting right away. For those already familiar with computing, the 
Commodore Plus/4 Encyclopedia contains a volume of useful 
information about the Commodore Plus/4 including a complete 
review of every command in the BASIC language built into the com- 
puter. This manual also contains explanations of the advanced 
features of the Commodore Plus/4 and tells you how to get the 
most out of these expanded capabilities. 

You can learn how to use the Commodore Plus/4's built-in 
integrated software packages— the spreadsheet, graphics, word 
processing and file manager — by reviewing the Commodore 
Plus/4 Integrated Software User's Manual, also included with your 
new computer. 



Cccommodore 



Commodore Business Machines, Inc.— Computer Systems Division 
1200 Wilson Drive. West Chester, PA 19380 



ISBN 0-88731-021-4